﻿
'/**********************************************************************
'/// <summary>
'// Name of File     :   ImporteSource.cs
'// Author           :   Sukhminder Singh
'// Create date      :   23rd Nov 2011
'/// </summary>
'************************************************************************/

Imports Crystal.CLL
Imports Infragistics.Win.UltraWinGrid
Imports CrystalDataHub.BLL
Imports CrystalDataHub.BLL.CrystalDataHub.BLL
Imports System.Text
Imports System.Globalization
Imports System.Text.RegularExpressions
Imports Infragistics.Win
Imports Crystal.CustomControls
Imports Infragistics.Win.UltraWinGrid.ExcelExport
Imports Infragistics.Documents.Excel
Imports CrystalCommon.BLL
Imports System.Data.SqlClient
Imports System.Diagnostics

Public Class ImporteSource
    Inherits BaseForm

#Region "Fields"

    Private mdtExcelData As New DataTable
    Private mdtColMapping As New DataTable
    Private mstrSelectedInvestorField As String = ""
    Private mstrSelectedFundField As String = ""
    Private mclsImporteSourceManager As New ImporteSourceManager
    Private mdtExcelOriginalData As New DataTable
    Private mblnAnyDataChange As Boolean = False
    Private mblnIsImportSuccessful As Boolean = False

    Public Event ReEnableDataHub(ByVal mblnIsImportSuccessful As Boolean)
    Public mintClientID As Int16
    Public mintProjectID As Integer
    Public mintListingID As Integer
    Public mintSourceTypeID As Int16
    Public mstrSourceName As String
    Public mintTemplateID As Int16
    Public mintEntityID As Integer
    Public mstrClientName As String
    Public mstrProjectName As String
    Public mstrListingName As String
    Public mstrSnapshotFilePath As String
    Public mstrSourceTypeCode As String
    Public mstrScreenStatus As String = ""
    Public mstrDataSourceName As String
    Public menmSourceTypeCode As SourceTypeCode

    Public mintRegularRadio As Int16
    Public mblnRetail As Boolean
    Public mblnCustodian As Boolean
    Public mblnCreateNew As Boolean
    Public mintAdvancedRadio As Int16
    Public mintRowNumber As Integer
    Public mstrHiddenColumns As String

    Private mstrSearchText As String = ""
    Private mstrCreateNew As String = "Create New"
    Private mstrUniversal As String = "Universal"
    Private mstrMergedAcquired As String = "M&A"
    Private mstrUniversalANDMergedAcquired As String = "Both"
    Private mblnIsAdvancedFilter As Boolean = False
    Private mstrScreenName As String = "Import EDS screen"

    Private mblnIsFirstTimeForRow As Boolean = True
    Private mblnIsFirstTimeForDoubt As Boolean = True
    Private mblnIsFirstTimeForInvChar As Boolean = True
    Private mblnIsFirstTimeForFundChar As Boolean = True
    Private mblnIsInvFundArea As Boolean = False
    Private mblnIsClientMappingExists As Boolean = False
    Private mblnIsUniversalMappingExists As Boolean = False

    Private mSelectedOperator As FilterLogicalOperator
    Private mintCustodianInvestorID As Integer
    Private mstrCustodianInvestor As String
    Private mintRetailMInvTypeID As Int16

    Private mstrMatchCol1 As String
    Private mstrMatchCol2 As String
    Private mstrMatchCol3 As String
    Private mstrMatchCol4 As String
    Private mstrMatchCol5 As String
    Private mstrPosition As String
    Private mstrExcelInvestorField As String = ""
    Private mstrExcelFundField As String = ""
    Private mintMatchColCount As Int16
    Private marrMatchCols(0) As String

    Private mintInvStatusCodeIndex As Integer
    Private mintFundStatusCodeIndex As Integer
    Private mintLinkCountIndex As Integer
    'Private mblnIsUniClientInvSameIndex As Integer
    'Private mblnIsUniClientFundSameIndex As Integer

    Public mstrMappedInvName As String
    Public mstrMappedFundName As String

    'Public mstrMappedInvName As String = "Mapped Inv. Name"
    'Public mstrMappedFundName As String = "Mapped Fund Name"

    Private SelectedRowBackColor(3) As Integer
    Dim marrExcludedFromChooser() As String = {"FundEntityID", "InvEntityID", "HasChangeLog", "LinkCount", "MInvestorTypeID", "UniFullName", "UniInvestorID", "UniFundID", _
                                                       "InvStatusCode", "FundStatusCode", "RowNumber", _
                                                       "OriginalInvestorID", "OriginalFundID", "InvestorID", "FundID", "EntityID", "ETemplateID", "ClientID", "UserID", _
                                                       "FilingDateCopy"}

    'Public marrExcludedFromFilters() As String = {"FundEntityID", "InvEntityID", "HasChangeLog", "LinkCount", "MInvestorTypeID", "UniInitials", "UniInvestorID", "UniFundID", _
    '                                               "InvStatusCode", "FundStatusCode", "RowNumber", _
    '                                               "OriginalInvestorID", "OriginalFundID", "InvestorID", "FundID", "EntityID", "ETemplateID", "ClientID", "Doubt", _
    '                                               "Initials"}
    Public marrExcludedFromFilters() As String
    Private mclrDelAndExtnct As Color
    Private mclrGridSelCellBackColor As Color
    Private mclrGridSelCellForeColor As Color

    Private menmAdvancedComparisonOperator As FilterComparisionOperator
    Private enmSearchTypes As SearchTypes
    Private enmMappingType As MappingType
    Public menmSnapshotType As SnapshotType

    Enum InvestorMappingChangesSource
        UnmapShortCut = 1
        CopyMappingShortCut = 2
        NewInvCreated = 3
        NewInvMarked = 4
        SuggestoinsFromInv = 5
        SuggestoinsFromFund = 6
        Restore = 7
        MarkCustodianTrue = 8
        MarkCustodianFalse = 9
    End Enum

    Enum FundMappingChangesSource
        UnmapShortCut = 1
        CopyMappingShortCut = 2
        NewFundCreated = 3
        NewFundMarked = 4
        Suggestoins = 5
        Restore = 6
        MarkCustodian = 7
    End Enum

    Enum SearchTypes
        SingleText = 1
        DoubleText = 2
        Blank = 3
        Doubt = 4
        BothUnmapped = 5
        FundMapped = 6
        InvestorMapped = 7
        BothMapped = 8
        ChangeLog = 9
    End Enum

    Enum MappingType
        Manual = 1
        Excel = 2
        Universal = 3
        Client = 4
    End Enum

    Enum SearchSummaryText
        Found = 1
        NoSuggestions = 2
        LessThanMin = 3
        NotValidForFunds = 4
    End Enum

#End Region

#Region "Constructors"

    Sub New(ByVal pdtExcelData As DataTable, ByVal pdtColMapping As DataTable, ByVal pintEntityID As Integer, ByVal pintProjectID As Integer)

        mdtExcelData = pdtExcelData
        mdtExcelOriginalData = pdtExcelData
        mdtColMapping = pdtColMapping
        mintEntityID = pintEntityID
        mintProjectID = pintProjectID
        ' This call is required by the designer.
        InitializeComponent()
        CheckScreenStatus()

        ' Add any initialization after the InitializeComponent() call.
    End Sub

#End Region

#Region "On Load"

    Private Sub ImporteSource_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CallOnLoad()
    End Sub

    ''' <summary>
    ''' To load the onload functions
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub CallOnLoad()
        'If the EDS is incomplated or Completed then load the mapping screen through snapshot
        Application.DoEvents()
        Dim lblnCanLoad As Boolean = True
        If menmSnapshotType = SnapshotType.Incomplete OrElse menmSnapshotType = SnapshotType.Complete Then
            If menmSnapshotType = SnapshotType.Complete Then
                btnImport.Enabled = False
                btnSave.Enabled = False
            End If
            lblnCanLoad = LoadSnapshot()
        End If
        If lblnCanLoad Then
            SetOnLoadControls()
            LoadGridData()
            InitCombo()
            LoadDropDowns()
            SnapshotSettings()
        End If
    End Sub

    ''' <summary>
    ''' To check if the mapping screen is already opened
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub CheckScreenStatus()
        Dim ldtScreentStatus As New DataTable
        Dim ldrScreentStatus As IDataReader
        Dim lblnCanShow As Boolean = False
        Try
            ldrScreentStatus = mclsImporteSourceManager.GetScreenStatus(mintEntityID)
            ldtScreentStatus.Load(ldrScreentStatus)
            CommonCLL.ChangeDataReaderDataTable(ldtScreentStatus)
            If ldtScreentStatus.Rows.Count >= 1 Then
                If ldtScreentStatus.Rows(0).Item("EDS") = True Then
                    If ldtScreentStatus.Rows(0).Item("UserID") = CommonCLL.UserID Then
                        If ldtScreentStatus.Rows(0).Item("FilePath").Equals("") = False Then
                            If ldtScreentStatus.Rows(0).Item("IsCompleted") = False Then
                                menmSnapshotType = SnapshotType.Incomplete
                            Else
                                menmSnapshotType = SnapshotType.Complete
                            End If
                            lblnCanShow = True
                        Else
                            mstrScreenStatus = MessageManager.GetMessage("EDS_MPNG_USE_SELF")
                        End If
                    Else
                        mstrScreenStatus = MessageManager.GetMessage("EDS_MPNG_USE_OTHR", ldtScreentStatus.Rows(0).Item("FullName"))
                    End If
                Else
                    lblnCanShow = True
                End If
            Else
                lblnCanShow = True
            End If
            'Set the screen status of the current project for the current user.
            If lblnCanShow Then
                ManageScreenStatus(mintEntityID, mintProjectID, CommonCLL.UserID, True, False, False)
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            ldtScreentStatus = Nothing
            ldrScreentStatus = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' To load the snapshot
    ''' </summary>
    ''' <remarks></remarks>
    Private Function LoadSnapshot() As Boolean
        Dim ldtSnapshots As DataTable = Nothing
        Dim ldrSnapshots As IDataReader = Nothing
        Dim lblnCanLoad As Boolean = True
        Dim lblnHasCorrectSnapshot = True
        Dim ldrTemplateMappings As IDataReader

        Try
            'If the SnapshotType is Complete, then set some attributes
            If menmSnapshotType = SnapshotType.Complete Then
                ldtSnapshots = New DataTable
                ldrSnapshots = mclsImporteSourceManager.GetSnapshots(mintListingID, mintEntityID, True)
                ldtSnapshots.Load(ldrSnapshots)
                CommonCLL.ChangeDataReaderDataTable(ldtSnapshots)
                If ldtSnapshots.Rows.Count = 0 Then
                    lblnHasCorrectSnapshot = False
                    MessageBox.Show("Mappings cannot be loaded as snapshot does not exist for the selected data source.", CommonCLL.mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                ElseIf ldtSnapshots.Rows.Count = 1 Then
                    mstrSourceName = ldtSnapshots.Rows(0).Item("Column Title")
                    mintSourceTypeID = ldtSnapshots.Rows(0).Item("SourceTypeID")

                    mintTemplateID = ldtSnapshots.Rows(0).Item("ETemplateID")
                    mstrSnapshotFilePath = ldtSnapshots.Rows(0).Item("FilePath")
                    If System.IO.File.Exists(mstrSnapshotFilePath) = False Then
                        MessageBox.Show("Mappings cannot be loaded as the saved path does not exist.", CommonCLL.mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                        Return False
                    End If
                End If
            End If

            'If EntityID found out to be 0, then Close the form
            If mintEntityID = 0 OrElse lblnHasCorrectSnapshot = False Then
                lblnCanLoad = False
                Me.Close()
            Else
                'If EntityID is valid, then get the template mapping for the saved Template and get the data from saved excel
                mdtColMapping = New DataTable
                mdtExcelData = New DataTable
                ldrTemplateMappings = mclsImporteSourceManager.GetTemplateMapping(mintTemplateID, mstrSourceTypeCode)
                mdtColMapping.Load(ldrTemplateMappings)
                CommonCLL.ChangeDataReaderDataTable(mdtColMapping)
                If menmSourceTypeCode = SourceTypeCode.PBC Then
                    SetColMappingPublicMatch(mdtColMapping)
                End If
                If GetDataFromExcel(False, mdtExcelData, mstrSnapshotFilePath) Is Nothing Then
                    lblnCanLoad = False
                End If
            End If
            Return lblnCanLoad
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
            Return False
        Finally
            ldtSnapshots = Nothing
            ldrSnapshots = Nothing
            ldrTemplateMappings = Nothing
            ldrSnapshots = Nothing
        End Try
    End Function

    ''' <summary>
    ''' Set the controls based on the saved snapshot
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SnapshotSettings()
        If menmSnapshotType = SnapshotType.Incomplete Then
            If mintRegularRadio = 1 Then
                rdContains.Checked = True
            ElseIf mintRegularRadio = 2 Then
                rdBeginsWith.Checked = True
            End If

            If mintAdvancedRadio = 1 Then
                rdAll.Checked = True
            ElseIf mintAdvancedRadio = 2 Then
                rdMultiLinks.Checked = True
            ElseIf mintAdvancedRadio = 3 Then
                rdChange.Checked = True
            ElseIf mintAdvancedRadio = 4 Then
                rdConflicts.Checked = True
            ElseIf mintAdvancedRadio = 5 Then
                rdFilteredResults.Checked = True
            End If

            chkRetail.Checked = mblnRetail
            chkCustodian.Checked = mblnCustodian
            chkCreateNew.Checked = mblnCreateNew

            If mintRowNumber >= 0 Then
                grdMapData.Rows(mintRowNumber).Activated = True
                'grdMapData.DisplayLayout.RowScrollRegions(0).ScrollRowIntoView(grdMapData.ActiveRow)
                CommonCLL.ScrollRowToMiddle(grdMapData.ActiveRow)
            End If

            'Hide the columns which were hidden at the time of saving
            For Each lCol As String In mstrHiddenColumns.Split("~")
                If grdMapData.DisplayLayout.Bands(0).Columns.Exists(lCol) Then
                    grdMapData.DisplayLayout.Bands(0).Columns(lCol).Hidden = True
                End If
            Next
        End If
    End Sub

    ''' <summary>
    ''' To set the controls on load
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SetOnLoadControls()
        Me.Text = "Crystal - " + mstrClientName + " - " + mstrProjectName + " - " + mstrSourceName + " - " + TitleManager.GetTitle("ImporteSource")
        'grdInvestor.EmptyDataText = "No data available"
        'grdFund.EmptyDataText = "No data available"
        txtSearch.Text = MessageManager.GetMessage("EDS_SEARCH")
        txtInvestor.Text = MessageManager.GetMessage("EDS_INVNAME_SEARCH")
        txtInvAddress.Text = MessageManager.GetMessage("EDS_ADD_SEARCH")
        txtFund.Text = MessageManager.GetMessage("EDS_FUNDNAME_SEARCH")
        txtFundAddress.Text = MessageManager.GetMessage("EDS_ADD_SEARCH")
        CommonCustomControls.IsValidString(StyleManager.GetStyle("GridSelRowBackColor"), SelectedRowBackColor)
        Dim Values As Integer() = New Integer(2) {}
        If CommonCustomControls.IsValidString(StyleManager.GetStyle("LabelForeColor"), Values) Then
            If lblSaveExit.Appearance.ForeColor <> Color.FromArgb(Values(0), Values(1), Values(2)) Then
                lblSaveExit.Appearance.ForeColor = Color.FromArgb(Values(0), Values(1), Values(2))
                lblSaveExit.Appearance.ForeColorDisabled = Color.FromArgb(Values(0), Values(1), Values(2))
            End If
        End If

        If CommonCustomControls.IsValidString(StyleManager.GetStyle("EDS_DeleteAndExtinctBackColor"), Values) Then
            mclrDelAndExtnct = Color.FromArgb(Values(0), Values(1), Values(2))
        End If

        If CommonCustomControls.IsValidString(StyleManager.GetStyle("GridSelCellBackColor"), Values) Then
            mclrGridSelCellBackColor = Color.FromArgb(Values(0), Values(1), Values(2))
        End If

        If CommonCustomControls.IsValidString(StyleManager.GetStyle("GridNonSelRowForeColor"), Values) Then
            mclrGridSelCellForeColor = Color.FromArgb(Values(0), Values(1), Values(2))
        End If

        rdContains.Checked = True
        rdAll.Checked = True
        rdFilteredResults.Enabled = False

        rdbInvNameContains.Checked = True
        rdbInvAddressContains.Checked = True
        rdbFundNameContains.Checked = True
        rdbFundAddressContains.Checked = True
        'lblAdvancedSearchText.Visible = False
        'lblAdvancedSearchValue.Visible = False
        If menmSourceTypeCode = SourceTypeCode.PBC Then
            grdMapData.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Select
        End If
        txtInvSearchChar.Text = 30
        txtFundSearchChar.Text = 15
        SetDefaultFieldValues()
        SetColumnNames()
        ReDim Preserve marrExcludedFromChooser(marrExcludedFromChooser.Length)
        marrExcludedFromChooser(marrExcludedFromChooser.Length - 1) = mstrMappedInvName
        ReDim Preserve marrExcludedFromChooser(marrExcludedFromChooser.Length)
        marrExcludedFromChooser(marrExcludedFromChooser.Length - 1) = mstrMappedFundName
    End Sub

#End Region

#Region "Init"

    ''' <summary>
    ''' To Initilize the combo boxes
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub InitCombo()
        With cmbInvestorField
            .ValueMember = "FieldID"
            .DisplayMember = "FieldName"
        End With

        With cmbFundField
            .ValueMember = "FieldID"
            .DisplayMember = "FieldName"
        End With
    End Sub

#End Region

#Region "Events"

#Region "Form Events"

    ''' <summary>
    ''' Check if the mapping screen of the project is already opened, before opening the snapshot
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub ImporteSource_Layout(ByVal sender As Object, ByVal e As System.Windows.Forms.LayoutEventArgs) Handles Me.Layout
        'CheckScreenStatus()
    End Sub

    ''' <summary>
    ''' Set the screen status for the current project
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub ImporteSource_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim ldrSaveExit As DialogResult
        Try
            If mblnAnyDataChange Then
                'Confirm from the user
                If menmSnapshotType = SnapshotType.Complete Then
                    ldrSaveExit = MessageBox.Show(MessageManager.GetMessage(DBResult.EDS_EXIT_CNFRM.ToString), CommonCLL.mstrMsgBoxCaption, MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
                Else
                    ldrSaveExit = MessageBox.Show(MessageManager.GetMessage(DBResult.SAVE_EXIT_CNFRM.ToString), MessageManager.GetMessage("CRYSTAL"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
                End If
                If ldrSaveExit = DialogResult.Yes AndAlso menmSnapshotType <> SnapshotType.Complete Then
                    btnSave.PerformClick()
                    'Me.Close()
                ElseIf ldrSaveExit = DialogResult.Cancel Then
                    e.Cancel = True
                    'Me.Close()
                End If
            End If
            If ldrSaveExit <> DialogResult.Cancel Then
                ManageScreenStatus(mintEntityID, mintProjectID, CommonCLL.UserID, False, False, False)
                'ManageScreenStatus(mintEntityID, False, CommonCLL.UserID)
                If menmSnapshotType = SnapshotType.Complete Then
                    RaiseEvent ReEnableDataHub(mblnIsImportSuccessful)
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            ldrSaveExit = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Disposes the form once closed
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub ImporteSource_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Me.Dispose()
    End Sub
#End Region

#Region "Grid Events"

#Region "Map Data"

    ''' <summary>
    ''' Do the suggestion search on Map Data row change
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdMapData_AfterRowActivate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grdMapData.AfterRowActivate
        Dim lintDefaultPerSearchLength As Integer
        Dim lintCellValueLength As Integer
        If grdMapData.ActiveRow.IsGroupByRow Then
            SetControlsForGroupByRow(False)
            Exit Sub
        Else
            SetControlsForGroupByRow(True)
            txtInvestor.Text = grdMapData.ActiveRow.GetCellValue(cmbInvestorField.SelectedItem("FieldName")).ToString.Trim
            txtFund.Text = grdMapData.ActiveRow.GetCellValue(cmbFundField.SelectedItem("FieldName")).ToString.Trim
            If menmSourceTypeCode = SourceTypeCode.PBC Then
                If grdMapData.ActiveRow.GetCellValue(mstrMatchCol4).ToString.Equals("") Then
                    SetControlsForInvestorRow(False)
                Else
                    SetControlsForInvestorRow(True)
                End If
            End If
        End If

        'Formulate the Investor and Fund search text
        If cmbInvestorField.SelectedItem IsNot Nothing Then
            lintCellValueLength = grdMapData.ActiveRow.GetCellValue(cmbInvestorField.SelectedItem("FieldName")).ToString.Trim.Length
            'lintCellValueLength = grdMapData.ActiveRow.Cells(cmbInvestorField.SelectedItem("FieldName")).Value.ToString.Trim.Length
            lintDefaultPerSearchLength = Math.Ceiling((lintCellValueLength * mintInvestorDefaultSearchPercentage) / 100)
            If lintDefaultPerSearchLength < 10 Then
                If lintCellValueLength >= 10 Then
                    lintDefaultPerSearchLength = mintMinSearchLength
                End If
            End If
            txtInvSearchChar.Text = lintDefaultPerSearchLength
            'txtInvSearchChar.Text = Math.Ceiling((grdMapData.ActiveRow.Cells(cmbInvestorField.SelectedItem("FieldName")).Value.ToString.Trim.Length * mintInvestorDefaultSearchPercentage) / 100).ToString
        End If

        If cmbFundField.SelectedItem IsNot Nothing Then
            'lintCellValueLength = grdMapData.ActiveRow.GetCellValue("FieldName").ToString.Trim.Length
            lintCellValueLength = grdMapData.ActiveRow.Cells(cmbFundField.SelectedItem("FieldName")).Value.ToString.Trim.Length
            lintDefaultPerSearchLength = Math.Ceiling((lintCellValueLength * mintFundDefaultSearchPercentage) / 100).ToString
            If lintDefaultPerSearchLength < 10 Then
                If lintCellValueLength >= 10 Then
                    lintDefaultPerSearchLength = mintMinSearchLength
                End If
            End If
            txtFundSearchChar.Text = lintDefaultPerSearchLength
            'txtFundSearchChar.Text = Math.Ceiling((grdMapData.ActiveRow.Cells(cmbFundField.SelectedItem("FieldName")).Value.ToString.Trim.Length * mintFundDefaultSearchPercentage) / 100).ToString
        End If
        ConductSuggestionSearch()
    End Sub

    ''' <summary>
    ''' To set the Back and Forecolor
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdMapData_AfterCellActivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdMapData.AfterCellActivate
        'If the currently selected cell is Mapped Investor and the investor is EXTINCT or DELETED, then set the backcolor to ligh pink.
        Dim lblnIsRegularBackColor As Boolean = True
        Dim lblnIsRegularForeColor As Boolean = True
        Dim lRow As UltraGridRow
        Try
            If grdMapData.ActiveCell.Column.Header.Caption.Equals(mstrMappedInvName) Then
                lRow = grdMapData.ActiveCell.Row
                If lRow.GetCellValue("InvStatusCode") IsNot DBNull.Value Then
                    If lRow.GetCellValue("InvStatusCode") = Crystal.CLL.EntityStatus.DELTE.ToString OrElse lRow.GetCellValue("InvStatusCode") = Crystal.CLL.EntityStatus.EXTNT.ToString Then
                        grdMapData.DisplayLayout.Override.ActiveCellAppearance.BackColor = grdMapData.DisplayLayout.Appearances("DelAndExtnct").BackColor 'mclrDelAndExtnct
                        lblnIsRegularBackColor = False
                    End If
                End If
                If lRow.GetCellValue("UniInvestorID").Equals(lRow.GetCellValue("InvestorID")) = False AndAlso lRow.GetCellValue("UniInvestorID") IsNot DBNull.Value Then
                    grdMapData.DisplayLayout.Override.ActiveCellAppearance.ForeColor = grdMapData.DisplayLayout.Appearances("UniInvestor").ForeColor  'Color.Red
                    lblnIsRegularForeColor = False
                End If

                'If the currently selected cell is Mapped Fund and the investor is EXTINCT or DELETED, then set the backcolor to ligh pink.
            ElseIf grdMapData.ActiveCell.Column.Header.Caption.Equals(mstrMappedFundName) Then
                lRow = grdMapData.ActiveCell.Row
                If lRow.GetCellValue("FundStatusCode") IsNot DBNull.Value Then
                    If lRow.GetCellValue("FundStatusCode") = Crystal.CLL.EntityStatus.DELTE.ToString OrElse lRow.GetCellValue("FundStatusCode") = Crystal.CLL.EntityStatus.EXTNT.ToString Then
                        grdMapData.DisplayLayout.Override.ActiveCellAppearance.BackColor = grdMapData.DisplayLayout.Appearances("DelAndExtnct").BackColor
                        lblnIsRegularBackColor = False
                    End If
                End If

                'If Universal Fund is different from the mapped Fund, then set the forecolor to red.
                If lRow.GetCellValue("UniFundID").Equals(lRow.GetCellValue("FundID")) = False AndAlso lRow.GetCellValue("UniFundID") IsNot DBNull.Value Then
                    grdMapData.DisplayLayout.Override.ActiveCellAppearance.ForeColor = grdMapData.DisplayLayout.Appearances("UniFund").ForeColor
                    lblnIsRegularForeColor = False
                End If
            End If
            'Otherwise, set the backcolor to normal
            If lblnIsRegularBackColor Then
                grdMapData.DisplayLayout.Override.ActiveCellAppearance.BackColor = grdMapData.DisplayLayout.Appearances("GridSelCellBackColor").BackColor 'mclrGridSelCellBackColor
            End If

            If lblnIsRegularForeColor Then
                grdMapData.DisplayLayout.Override.ActiveCellAppearance.ForeColor = grdMapData.DisplayLayout.Appearances("GridSelCellForeColor").ForeColor  'mclrGridSelCellForeColor
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            lRow = Nothing
        End Try
    End Sub


    ''' <summary>
    ''' Set the column chooser form's properties
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdMapData_BeforeColumnChooserDisplayed(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeColumnChooserDisplayedEventArgs) Handles grdMapData.BeforeColumnChooserDisplayed
        ' UltraGrid fires BeforeColumnChooserDisplayed event whenever it's about to
        ' display the column chooser dialog, either via the ColumnChooserButton or
        ' when the ShowColumnChooser method is called on the UltraGrid.

        ' You can access the column chooser dialog that will be displayed using the
        ' Dialog property. Here you can change location, size among other settings
        ' of the dialog.
        e.Dialog.Text = "Column Chooser"
        e.Dialog.Size = New Size(200, 450)
        e.Dialog.ColumnChooserControl.ColumnDisplayOrder = ColumnDisplayOrder.SameAsGrid
        e.Dialog.Location = New Point(btnColumnList.Location.X - 80, btnColumnList.Location.Y + 100)
        ' By default UltraGrid retains the column chooser dialog instance. You can 
        ' set the DisposeOnClose to True to cause the UltraGrid to dispose the dialog 
        ' when it's closed by the user.
        'e.Dialog.DisposeOnClose = DefaultableBoolean.True

        ' You can use the ColumnChooserControl property of the dialog to access the
        ' column chooser control that actually displays the list of the columns.
        e.Dialog.ColumnChooserControl.MultipleBandSupport = MultipleBandSupport.SingleBandOnly
        e.Dialog.ColumnChooserControl.Style = ColumnChooserStyle.AllColumnsWithCheckBoxes

        ' By default column chooser attempts to look similar to the source grid whose
        ' columns are being displayed in the column chooser. You can set the
        ' SyncLookWithSourceGrid to false to prevent column chooser from doing this
        ' This will also ensure that the column chooser won't override your appearance
        ' settings.
        e.Dialog.ColumnChooserControl.SyncLookWithSourceGrid = False
        e.Dialog.ColumnChooserControl.DisplayLayout.Appearance.BackColor = SystemColors.Window
    End Sub

    ''' <summary>
    ''' To check if the column to be hidden is Mapped Inv. or Mapped Fund, then don't allow it
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdMapData_BeforeColPosChanged(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeColPosChangedEventArgs) Handles grdMapData.BeforeColPosChanged
        'Try
        '    If e.ColumnHeaders.Length > 0 Then
        '        If (e.ColumnHeaders(0).Column.Key = cmbInvestorField.SelectedItem("FieldName") OrElse e.ColumnHeaders(0).Column.Key = cmbFundField.SelectedItem("FieldName")) AndAlso grdMapData.DisplayLayout.Bands(0).Columns(e.ColumnHeaders(0).Column.Key).Hidden = False Then
        '            Me.ShowMessageBox(DBResult.EDS_SUGGESTION_COL)
        '            e.Cancel = True
        '        End If
        '    End If
        'Catch ex As Exception
        '    Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        'End Try
    End Sub

    ''' <summary>
    ''' To show the tooltip once on load.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdMapData_MouseEnterElement(ByVal sender As Object, ByVal e As UIElementEventArgs) Handles grdMapData.MouseEnterElement
        Dim acell As UltraGridCell
        Dim tipInfo As Infragistics.Win.UltraWinToolTip.UltraToolTipInfo
        Dim arow As UltraGridRow
        Try
            'To show the tooltip once on mouse hovering on Doubt column
            If mblnIsFirstTimeForDoubt Then
                acell = e.Element.GetContext(GetType(Infragistics.Win.UltraWinGrid.UltraGridCell))
                If Not acell Is Nothing Then
                    If acell.Column.Header.Caption = "Doubts" Then
                        tipInfo = New Infragistics.Win.UltraWinToolTip.UltraToolTipInfo(MessageManager.GetMessage(DBResult.EDS_MARK_DOUBT_1.ToString) + Environment.NewLine + MessageManager.GetMessage(DBResult.EDS_MARK_DOUBT_2.ToString), ToolTipImage.Info, "Shortcut", DefaultableBoolean.True)
                        tipInfo.Appearance.BackColor = grdMapData.DisplayLayout.Appearances("ToolTipInfo").BackColor  'Color.FromArgb(246, 214, 115)
                        UltraToolTipManager1.Enabled = True
                        UltraToolTipManager1.SetUltraToolTip(sender, tipInfo)
                        UltraToolTipManager1.ShowToolTip(sender)
                        mblnIsFirstTimeForDoubt = False
                        Exit Sub
                    End If
                End If
            End If
            'To show the tooltip once on mouse hovering on the selected row
            If mblnIsFirstTimeForRow Then
                If grdMapData.ActiveRow IsNot Nothing Then
                    arow = e.Element.GetContext(GetType(Infragistics.Win.UltraWinGrid.UltraGridRow))
                    If arow IsNot Nothing Then
                        If grdMapData.ActiveRow.Index = arow.Index Then
                            tipInfo = New Infragistics.Win.UltraWinToolTip.UltraToolTipInfo(MessageManager.GetMessage(DBResult.EDS_COPY_CONTENT.ToString) + Environment.NewLine + Environment.NewLine + "Press:" + Environment.NewLine + MessageManager.GetMessage(DBResult.EDS_REMOVE_INV_MAPPING.ToString) + Environment.NewLine + MessageManager.GetMessage(DBResult.EDS_REMOVE_FUND_MAPPING.ToString) + Environment.NewLine + MessageManager.GetMessage(DBResult.EDS_APPLY_INV_MAPPING.ToString) + Environment.NewLine + MessageManager.GetMessage(DBResult.EDS_APPLY_FUND_MAPPING.ToString) + Environment.NewLine + MessageManager.GetMessage(DBResult.EDS_APPLY_INVFUND_MAPPING.ToString), ToolTipImage.Info, "Shortcuts", DefaultableBoolean.True)
                            tipInfo.Appearance.BackColor = grdMapData.DisplayLayout.Appearances("ToolTipInfo").BackColor  'Color.FromArgb(246, 214, 115)
                            UltraToolTipManager1.Enabled = True
                            UltraToolTipManager1.SetUltraToolTip(sender, tipInfo)
                            UltraToolTipManager1.ShowToolTip(sender)
                            mblnIsFirstTimeForRow = False
                            Exit Sub
                        End If
                    End If
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            acell = Nothing
            tipInfo = Nothing
            arow = Nothing
        End Try
    End Sub

    Private Sub grdMapData_MouseLeaveElement(ByVal sender As System.Object, ByVal e As Infragistics.Win.UIElementEventArgs) Handles grdMapData.MouseLeaveElement
        UltraToolTipManager1.Enabled = False
    End Sub

    ''' <summary>
    ''' To exclude the columns from the column chooser
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdMapData_InitializeLayout(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles grdMapData.InitializeLayout
        If menmSnapshotType = SnapshotType.Incomplete OrElse menmSnapshotType = SnapshotType.Complete Then
            grdMapData.DisplayLayout.Bands(0).Columns("Doubts").Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox
        End If

        grdMapData.DisplayLayout.Bands(0).Columns(mstrPosition).Format = "###,###,###"

        e.Layout.Override.FilterUIType = FilterUIType.HeaderIcons
        ' Turn on row filtering functionality.
        e.Layout.Override.AllowRowFiltering = DefaultableBoolean.True
        e.Layout.Override.RowFilterAction = RowFilterAction.HideFilteredOutRows

        e.Layout.Override.FilterOperandStyle = FilterOperandStyle.Combo

        'e.Layout.Bands(0).Columns("Boolean 1").FilterOperandStyle = FilterOperandStyle.DropDownList

        Dim lDelAndExtnctAppereance As Appearance
        Dim lGridSelCellAppereance As Appearance
        Dim lGridSelCellFCAppereance As Appearance
        Dim lUniInvestorAppereance As Appearance
        Dim lMapInvestorAppereance As Appearance
        Dim lUniFundAppereance As Appearance
        Dim lMapFundAppereance As Appearance
        Dim lToolTipInfoAppereance As Appearance
        Dim lRedBorderAppereance As Appearance
        Try
            lDelAndExtnctAppereance = e.Layout.Appearances.Add("DelAndExtnct")
            lDelAndExtnctAppereance.BackColor = mclrDelAndExtnct

            lGridSelCellAppereance = e.Layout.Appearances.Add("GridSelCellBackColor")
            lGridSelCellAppereance.BackColor = mclrGridSelCellBackColor

            lGridSelCellFCAppereance = e.Layout.Appearances.Add("GridSelCellForeColor")
            lGridSelCellFCAppereance.ForeColor = mclrGridSelCellForeColor

            lUniInvestorAppereance = e.Layout.Appearances.Add("UniInvestor")
            lUniInvestorAppereance.ForeColor = Color.Red

            lMapInvestorAppereance = e.Layout.Appearances.Add("MapInvestor")
            lMapInvestorAppereance.ForeColor = Color.Black

            lUniFundAppereance = e.Layout.Appearances.Add("UniFund")
            lUniFundAppereance.ForeColor = Color.Red

            lMapFundAppereance = e.Layout.Appearances.Add("MapFund")
            lMapFundAppereance.ForeColor = Color.Black

            lToolTipInfoAppereance = e.Layout.Appearances.Add("ToolTipInfo")
            lToolTipInfoAppereance.ForeColor = Color.FromArgb(246, 214, 115)

            lRedBorderAppereance = e.Layout.Appearances.Add("RedBorder")
            lRedBorderAppereance.BorderColor = Color.Red

        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            lDelAndExtnctAppereance = Nothing
            lGridSelCellAppereance = Nothing
            lGridSelCellFCAppereance = Nothing
            lUniInvestorAppereance = Nothing
            lMapInvestorAppereance = Nothing
            lUniFundAppereance = Nothing
            lMapFundAppereance = Nothing
            lToolTipInfoAppereance = Nothing
            lRedBorderAppereance = Nothing
        End Try
    End Sub

    ''' <summary>
    '''  To set the fore and back color.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdMapData_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles grdMapData.InitializeRow
        Dim lintActiveCellIndex As Integer
        Try
            lintActiveCellIndex = -1
            If grdMapData.ActiveCell IsNot Nothing Then
                lintActiveCellIndex = grdMapData.ActiveCell.Column.Index
            End If
            'If e.ReInitialize = False Then
            'If the cell is Mapped Investor and it is EXTINCT or DELETED, then set the backcolor to ligh pink.
            If e.Row.GetCellValue("InvStatusCode") IsNot DBNull.Value Then
                If e.Row.GetCellValue("InvStatusCode") = Crystal.CLL.EntityStatus.DELTE.ToString OrElse e.Row.GetCellValue("InvStatusCode") = Crystal.CLL.EntityStatus.EXTNT.ToString Then
                    e.Row.Cells(mstrMappedInvName).Appearance.BackColor = grdMapData.DisplayLayout.Appearances("DelAndExtnct").BackColor  'mclrDelAndExtnct
                Else
                    e.Row.Cells(mstrMappedInvName).Appearance.BackColor = grdMapData.DisplayLayout.Appearances("GridSelCellBackColor").BackColor
                    If e.ReInitialize Then
                        If e.Row.Band.Columns(mstrMappedInvName).Index = lintActiveCellIndex Then
                            grdMapData.DisplayLayout.Override.ActiveCellAppearance.BackColor = grdMapData.DisplayLayout.Appearances("GridSelCellBackColor").BackColor  'mclrGridSelCellBackColor
                        End If
                    End If
                End If
            End If
            'If the cell is Mapped Fund and it is EXTINCT or DELETED, then set the backcolor to ligh pink.
            If e.Row.GetCellValue("FundStatusCode") IsNot DBNull.Value Then
                If e.Row.GetCellValue("FundStatusCode") = Crystal.CLL.EntityStatus.DELTE.ToString OrElse e.Row.GetCellValue("FundStatusCode") = Crystal.CLL.EntityStatus.EXTNT.ToString Then
                    e.Row.Cells(mstrMappedFundName).Appearance.BackColor = grdMapData.DisplayLayout.Appearances("DelAndExtnct").BackColor 'mclrDelAndExtnct
                Else
                    'grdMapData.DisplayLayout.Override.ActiveCellAppearance.BackColor = mclrGridSelCellBackColor
                    e.Row.Cells(mstrMappedFundName).Appearance.BackColor = grdMapData.DisplayLayout.Appearances("GridSelCellBackColor").BackColor 'mclrGridSelCellBackColor
                    If e.ReInitialize Then
                        If e.Row.Band.Columns(mstrMappedFundName).Index = lintActiveCellIndex Then
                            grdMapData.DisplayLayout.Override.ActiveCellAppearance.BackColor = grdMapData.DisplayLayout.Appearances("GridSelCellBackColor").BackColor 'mclrGridSelCellBackColor
                        End If
                    End If
                End If
            End If

            ''If Universal Investor is different from the mapped Investor, then set the forecolor to red.
            'If e.Row.Cells("UniInvestorID").Value.Equals(e.Row.Cells("InvestorID").Value) = False Then
            '    If e.Row.Cells("UniInvestorID").Value.Equals(e.Row.Cells("InvestorID").Value) = False Then
            '        e.Row.Cells(mstrMappedInvName).Appearance.ForeColor = Color.Red
            '    End If
            'End If

            ''If Universal Fund is different from the mapped Fund, then set the forecolor to red.
            'If e.Row.Cells("UniFundID").Value.Equals(e.Row.Cells("FundID").Value) = False Then
            '    If e.Row.Cells("UniFundID").Value.Equals(e.Row.Cells("FundID").Value) = False Then
            '        e.Row.Cells(mstrMappedFundName).Appearance.ForeColor = Color.Red
            '    End If
            'End If

            'If Universal Investor is different from the mapped Investor, then set the forecolor to red.
            If e.Row.GetCellValue("UniInvestorID").Equals(e.Row.GetCellValue("InvestorID")) = False AndAlso e.Row.GetCellValue("UniInvestorID") IsNot DBNull.Value Then
                grdMapData.DisplayLayout.Override.ActiveCellAppearance.ForeColor = grdMapData.DisplayLayout.Appearances("UniInvestor").ForeColor  'Color.Red
                e.Row.Cells(mstrMappedInvName).Appearance.ForeColor = grdMapData.DisplayLayout.Appearances("UniInvestor").ForeColor
            Else
                grdMapData.DisplayLayout.Override.ActiveCellAppearance.ForeColor = grdMapData.DisplayLayout.Appearances("MapInvestor").ForeColor
                e.Row.Cells(mstrMappedInvName).Appearance.ForeColor = grdMapData.DisplayLayout.Appearances("MapInvestor").ForeColor
            End If

            ''If Universal Fund is different from the mapped Fund, then set the forecolor to red.
            If e.Row.GetCellValue("UniFundID").Equals(e.Row.GetCellValue("FundID")) = False AndAlso e.Row.GetCellValue("UniFundID") IsNot DBNull.Value Then
                grdMapData.DisplayLayout.Override.ActiveCellAppearance.ForeColor = grdMapData.DisplayLayout.Appearances("UniFund").ForeColor
                e.Row.Cells(mstrMappedFundName).Appearance.ForeColor = grdMapData.DisplayLayout.Appearances("UniFund").ForeColor
            Else
                grdMapData.DisplayLayout.Override.ActiveCellAppearance.ForeColor = grdMapData.DisplayLayout.Appearances("MapFund").ForeColor
                e.Row.Cells(mstrMappedFundName).Appearance.ForeColor = grdMapData.DisplayLayout.Appearances("MapFund").ForeColor
            End If
            'End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            lintActiveCellIndex = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Copy the cell's content to clipboard
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdMapData_DoubleClickCell(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.DoubleClickCellEventArgs) Handles grdMapData.DoubleClickCell
        grdMapData.PerformAction(UltraGridAction.Copy, False, False)
    End Sub

    ''' <summary>
    ''' To set the filter radio buttons
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdMapData_AfterRowFilterChanged(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.AfterRowFilterChangedEventArgs) Handles grdMapData.AfterRowFilterChanged
        e.Column.Band.ColumnFilters.LogicalOperator = FilterLogicalOperator.And
        'On Advanced filter, hide the AdvancedFilter button and check the FilterResults radio button
        If rdAll.Checked OrElse rdMultiLinks.Checked OrElse rdChange.Checked OrElse rdConflicts.Checked Then
            If rdAll.Checked Then
                btnAdvanceFilter.Visible = False
            End If
            rdFilteredResults.Checked = True
        End If
    End Sub

    Private Sub grdMapData_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles grdMapData.MouseUp
        Dim mousePoint As Point = Nothing
        Try
            'Restore Originial Investor and Fund is not available in case of Universal mapping.
            If enmMappingType = MappingType.Universal Then Exit Sub
            If e.Button = Windows.Forms.MouseButtons.Right Then
                mousePoint = New Point(e.X, e.Y)
                If grdMapData.ActiveRow Is Nothing Then Exit Sub
                Dim lintOriginalInvestorID As Integer
                Dim lintInvestorID As Integer
                Dim lintOriginalFundID As Integer
                Dim lintFundID As Integer

                'Enable/Disable menu items if one or zero row is selected
                If grdMapData.Selected.Rows.Count = 0 OrElse grdMapData.Selected.Rows.Count = 1 Then
                    If grdMapData.ActiveRow.GetCellValue("OriginalInvestorID") Is DBNull.Value Then
                        lintOriginalInvestorID = 0
                    Else
                        lintOriginalInvestorID = grdMapData.ActiveRow.GetCellValue("OriginalInvestorID")
                    End If

                    If grdMapData.ActiveRow.GetCellValue("InvestorID") Is DBNull.Value Then
                        lintInvestorID = 0
                    Else
                        lintInvestorID = grdMapData.ActiveRow.GetCellValue("InvestorID")
                    End If

                    If grdMapData.ActiveRow.GetCellValue("OriginalFundID") Is DBNull.Value Then
                        lintOriginalFundID = 0
                    Else
                        lintOriginalFundID = grdMapData.ActiveRow.GetCellValue("OriginalFundID")
                    End If

                    If grdMapData.ActiveRow.GetCellValue("FundID") Is DBNull.Value Then
                        lintFundID = 0
                    Else
                        lintFundID = grdMapData.ActiveRow.GetCellValue("FundID")
                    End If

                    'If the Original Investor and Mapped Investor is same, then disable Restore Original Investor menu item.
                    If lintOriginalInvestorID = lintInvestorID Then
                        mnuRestoreOriginalInvestor.Enabled = False
                    Else
                        mnuRestoreOriginalInvestor.Enabled = True
                    End If

                    'If the Original Fund and Mapped Fund is same, then disable Restore Original Fund menu item.
                    If lintOriginalFundID = lintFundID Then
                        mnuRestoreOriginalFund.Enabled = False
                    Else
                        mnuRestoreOriginalFund.Enabled = True
                    End If
                Else
                    mnuRestoreOriginalInvestor.Enabled = True
                    mnuRestoreOriginalFund.Enabled = True
                End If
                ShowContextMenu(mousePoint)
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            mousePoint = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' If multiple rows are selected, then investor and fund grid should be blank
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdMapData_AfterSelectChange(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.AfterSelectChangeEventArgs) Handles grdMapData.AfterSelectChange
        If grdMapData.Selected.Rows.Count > 1 Then
            grdInvestor.DataSource = Nothing
            grdFund.DataSource = Nothing
        End If
    End Sub

    ''' <summary>
    ''' To Tick/Untick the Doubt column.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdMapData_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdMapData.Click
        Try
            'Tick/Un-Tick funcationality
            If grdMapData.ActiveCell IsNot Nothing Then
                If (grdMapData.ActiveCell.Column.Header.Caption = "Doubts") Then
                    'If no row is selected, then make the active row as selected
                    Dim lblnZeroIsSelectedRow As Boolean = False
                    If grdMapData.Selected.Rows.Count = 0 Then
                        lblnZeroIsSelectedRow = True
                        grdMapData.Rows(grdMapData.ActiveRow.Index).Selected = True
                    End If
                    'To Tick/Un-tick the Doubts.
                    SetDoubtStatusForMapData()

                    'If row was selected through code, then unselect it.
                    If lblnZeroIsSelectedRow Then
                        grdMapData.Rows(grdMapData.ActiveRow.Index).Selected = False
                    End If
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        End Try
    End Sub

    ''' <summary>
    ''' To run the Regular Search, Remove Investor/Fund Mapping, Copy Investor/Fund mappings in other rows and Tick-Untick Doubts through shortcut.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdMapData_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles grdMapData.KeyDown
        Dim ldtAttributes As DataTable = Nothing
        Dim larrRow() As DataRow = Nothing
        Dim larrTickedRow() As DataRow = Nothing
        Dim lblnIsInvestor As Boolean = False
        Dim lstrUniColName As String = ""
        Dim lstrColName As String = ""

        Dim lblnZeroIsSelectedRow As Boolean = False
        Dim lstrQuery As String
        Dim lblnIsUniversalTickable As Boolean = False

        Dim lintFirstSelectedRow As Integer
        Dim lblnIsFundRow As Boolean

        If grdMapData.ActiveRow.IsGroupByRow Then
            SetControlsForGroupByRow(False)
            Exit Sub
        Else
            SetControlsForGroupByRow(True)
        End If
        Try
            'To do the regular search and select/highlight the next occurance of the searched text
            If e.KeyCode = Keys.Enter AndAlso mstrSearchText <> "" Then
                SelectNextPhraseOccurance(grdMapData, grdMapData.ActiveRow.Index, mstrSearchText)
            ElseIf e.Modifiers = Keys.Control Then
                'Sort the selected rows to inherit the top row's attribute for the other selected rows.
                grdMapData.Selected.Rows.Sort()

                'If no row is selected, then make the active row as selected
                If grdMapData.Selected.Rows.Count = 0 Then
                    lblnZeroIsSelectedRow = True
                    grdMapData.Rows(grdMapData.ActiveRow.Index).Selected = True
                End If

                'To Tick-Untick the doubts for the selected rows.
                If e.KeyCode = Keys.D Then
                    SetDoubtStatusForMapData()
                ElseIf e.KeyCode = Keys.P Then
                    'To mark the selected Investor as Custodian
                    chkMarkCustodian.Checked = True
                    MarkCustodian()
                    'To unmap the selected Investor and Fund
                ElseIf e.KeyCode = Keys.I OrElse e.KeyCode = Keys.F Then

                    ldtAttributes = New DataTable


                    If e.KeyCode = Keys.I Then
                        lblnIsInvestor = True
                        lstrUniColName = "UniInvestorID"
                        lstrColName = "InvestorID"
                    ElseIf e.KeyCode = Keys.F Then
                        lstrUniColName = "UniFundID"
                        lstrColName = "FundID"
                    End If

                    'On pressing Ctrl+I and Ctrl+F, system will get other attributes of the relevant Universal records, if applicable and overwrite the selected 
                    'row's attributes with them.
                    ldtAttributes = GetOtherAttributes(lstrColName, lstrUniColName, lblnIsInvestor)
                    If e.KeyCode = Keys.I Then
                        For Each lRow As UltraGridRow In grdMapData.Selected.Rows
                            'Save the UserID, because user who is changing the mapping needs to be logged
                            'lRow.Cells("Full Name").Value = CommonCLL.UserFullName
                            'lRow.Cells("UserID").Value = CommonCLL.UserID
                            If lRow.GetCellValue("InvestorID") Is DBNull.Value Then Continue For
                            'If the selected mapped invetor is a universal one Or if universal investor does not exist, then unmap the record
                            If lRow.GetCellValue("UniInvestorID").Equals(lRow.GetCellValue("InvestorID")) OrElse lRow.GetCellValue("UniInvestorID") Is DBNull.Value Then
                                SetInvestorRelatedFields(lRow, Nothing, Nothing, InvestorMappingChangesSource.UnmapShortCut)

                            Else
                                'If the selected mapped invetor is not universal, then map the record as Universal
                                lstrQuery = "InvestorID =" + lRow.GetCellValue("UniInvestorID").ToString
                                larrRow = ldtAttributes.Select(lstrQuery)
                                If larrRow.Length = 1 Then
                                    SetInvestorRelatedFields(lRow, larrRow(0), Nothing, InvestorMappingChangesSource.UnmapShortCut)
                                End If
                            End If
                        Next
                        If grdInvestor.DataSource IsNot Nothing Then
                            'Check if, some row is ticked in Investor grid
                            larrTickedRow = CType(grdInvestor.DataSource, DataTable).Select("M=True")
                            If larrTickedRow.Length = 1 Then
                                'Untick the ticked row
                                'CType(grdInvestor.DataSource, DataTable).

                                '''''''''''''''''''''''''''''''''''''''''''''
                                'To avoid Sorting issues
                                larrTickedRow(0).Item("M") = False
                                'grdInvestor.Rows.GetRowWithListIndex(CType(grdInvestor.DataSource, DataTable).Rows.IndexOf(larrTickedRow(0))).Cells("M").Value = False
                                'grdInvestor.Rows(CType(grdInvestor.DataSource, DataTable).Rows.IndexOf(larrTickedRow(0))).Cells("M").Value = False
                                '''''''''''''''''''''''''''''''''''''''''''''

                                'If the unticked row is a non-universal, it means Universal row is tickable
                                If larrTickedRow(0).Item("UniRowIndex") <> 1 Then
                                    lblnIsUniversalTickable = True
                                End If
                            Else
                                'If there is no ticked row, it means the Universal row is tickable
                                lblnIsUniversalTickable = True
                            End If

                            If lblnIsUniversalTickable Then
                                'If Universal row is tickable then find the index of that row and tick it.
                                larrRow = CType(grdInvestor.DataSource, DataTable).Select("UniRowIndex=1")
                                If larrRow.Length = 1 Then
                                    '''''''''''''''''''''''''''''''''''''''''''''
                                    'To avoid Sorting issues
                                    larrRow(0).Item("M") = True
                                    'grdInvestor.Rows.GetRowWithListIndex(CType(grdInvestor.DataSource, DataTable).Rows.IndexOf(larrRow(0))).Cells("M").Value = True
                                    'grdInvestor.Rows(CType(grdInvestor.DataSource, DataTable).Rows.IndexOf(larrRow(0))).Cells("M").Value = True
                                    '''''''''''''''''''''''''''''''''''''''''''''
                                End If
                            End If
                            CType(grdInvestor.DataSource, DataTable).AcceptChanges()
                        End If

                    ElseIf e.KeyCode = Keys.F Then
                        For Each lRow As UltraGridRow In grdMapData.Selected.Rows
                            'Save the UserID, because user who is changing the mapping needs to be logged
                            'lRow.Cells("UserID").Value = CommonCLL.UserID
                            'lRow.Cells("Full Name").Value = CommonCLL.UserFullName
                            If lRow.GetCellValue("FundID") Is DBNull.Value Then Continue For
                            'If the selected mapped fund is a universal one, then unmap the record
                            If lRow.GetCellValue("UniFundID").Equals(lRow.GetCellValue("FundID")) OrElse lRow.GetCellValue("UniFundID") Is DBNull.Value Then
                                SetFundRelatedFields(lRow, Nothing, Nothing, FundMappingChangesSource.UnmapShortCut)
                            Else
                                'If the selected mapped fund is not universal, then map the record as Universal
                                lstrQuery = "FundID =" + lRow.GetCellValue("UniFundID").ToString
                                larrRow = ldtAttributes.Select(lstrQuery)
                                If larrRow.Length = 1 Then
                                    SetFundRelatedFields(lRow, larrRow(0), Nothing, FundMappingChangesSource.UnmapShortCut)
                                End If
                            End If
                        Next
                        If grdFund.DataSource IsNot Nothing Then
                            'Check if, some row is ticked in fund grid
                            larrTickedRow = CType(grdFund.DataSource, DataTable).Select("M=True")
                            If larrTickedRow.Length = 1 Then
                                'Untick the ticked row
                                '''''''''''''''''''''''''''''''''''''''''''''
                                'To avoid Sorting issues
                                larrTickedRow(0).Item("M") = False
                                'grdFund.Rows(CType(grdFund.DataSource, DataTable).Rows.IndexOf(larrTickedRow(0))).Cells("M").Value = False
                                '''''''''''''''''''''''''''''''''''''''''''''

                                'If the unticked row is a non-universal, it means Universal row is tickable
                                If larrTickedRow(0).Item("UniRowIndex") <> 1 Then
                                    lblnIsUniversalTickable = True
                                End If
                            Else
                                'If there is no ticked row, it means the Universal row is tickable
                                lblnIsUniversalTickable = True
                            End If

                            If lblnIsUniversalTickable Then
                                'If Universal row is tickable then find the index of that row and tick it.
                                larrRow = CType(grdFund.DataSource, DataTable).Select("UniRowIndex=1")
                                If larrRow.Length = 1 Then
                                    '''''''''''''''''''''''''''''''''''''''''''''
                                    'To avoid Sorting issues
                                    larrRow(0).Item("M") = True
                                    'grdFund.Rows(CType(grdFund.DataSource, DataTable).Rows.IndexOf(larrRow(0))).Cells("M").Value = True
                                End If
                            End If
                            CType(grdFund.DataSource, DataTable).AcceptChanges()
                        End If
                    End If
                    CType(grdMapData.DataSource, DataTable).AcceptChanges()
                ElseIf e.KeyCode = Keys.D1 OrElse e.KeyCode = Keys.D2 OrElse e.KeyCode = Keys.D3 Then
                    lintFirstSelectedRow = grdMapData.Selected.Rows(0).Index
                    lblnIsFundRow = True
                    If menmSourceTypeCode = SourceTypeCode.PBC Then
                        If grdMapData.ActiveRow.GetCellValue(mstrMatchCol4).ToString.Equals("") Then
                            lblnIsFundRow = False
                        End If
                    End If

                    'To copy the first selcted investor's mapping in other selected rows
                    If e.KeyCode = Keys.D1 Then
                        For Each lRow As UltraGridRow In grdMapData.Selected.Rows
                            If lRow.Index <> lintFirstSelectedRow Then
                                SetInvestorRelatedFields(lRow, Nothing, grdMapData.Rows(lintFirstSelectedRow), InvestorMappingChangesSource.CopyMappingShortCut)
                            End If
                        Next
                        'To copy the first selcted fund's mapping in other selected rows
                    ElseIf e.KeyCode = Keys.D2 Then
                        If lblnIsFundRow Then
                            For Each lRow As UltraGridRow In grdMapData.Selected.Rows
                                If lRow.Index <> lintFirstSelectedRow Then
                                    SetFundRelatedFields(lRow, Nothing, grdMapData.Rows(lintFirstSelectedRow), FundMappingChangesSource.CopyMappingShortCut)
                                End If
                            Next
                        End If
                        'To copy the first selcted investor/fund's mapping in other selected rows
                    ElseIf e.KeyCode = Keys.D3 Then
                        For Each lRow As UltraGridRow In grdMapData.Selected.Rows
                            If lRow.Index <> lintFirstSelectedRow Then
                                SetInvestorRelatedFields(lRow, Nothing, grdMapData.Rows(lintFirstSelectedRow), InvestorMappingChangesSource.CopyMappingShortCut)
                                If lblnIsFundRow Then
                                    SetFundRelatedFields(lRow, Nothing, grdMapData.Rows(lintFirstSelectedRow), FundMappingChangesSource.CopyMappingShortCut)
                                End If
                            End If
                        Next
                    End If
                    CType(grdMapData.DataSource, DataTable).AcceptChanges()
                    grdMapData.UpdateData()
                    If lblnZeroIsSelectedRow Then
                        grdMapData.Rows(grdMapData.ActiveRow.Index).Selected = False
                    End If
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            ldtAttributes = Nothing
            larrRow = Nothing
            larrTickedRow = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Check the status if there are any changes in the grid
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdMapData_BeforeRowUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CancelableRowEventArgs) Handles grdMapData.BeforeRowUpdate
        CommonCLL.CheckUpdateStatus(mblnAnyDataChange, grdMapData)
        If btnImport.Enabled = False AndAlso menmSnapshotType = SnapshotType.Complete AndAlso mblnAnyDataChange Then
            btnImport.Enabled = True
        End If
    End Sub

    ''' <summary>
    ''' Check the status if there are any changes in the grid
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdMapData_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdMapData.LostFocus
        CommonCLL.CheckUpdateStatus(mblnAnyDataChange, grdMapData)
        If btnImport.Enabled = False AndAlso menmSnapshotType = SnapshotType.Complete AndAlso mblnAnyDataChange Then
            btnImport.Enabled = True
        End If
    End Sub

#End Region

#Region "Investors"

    ''' <summary>
    ''' To set the back and forecolor of the selected cell
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdInvestor_AfterCellActivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdInvestor.AfterCellActivate
        Dim lblnIsRegularCell As Boolean = True
        Dim lRow As UltraGridRow = grdInvestor.ActiveCell.Row
        'If the selected cell is Investor Name and is Extinct OR Delete then set the backcolor to Pink
        If grdInvestor.ActiveCell.Column.Header.Caption.Equals("Name") Then
            If lRow.GetCellValue("InvStatusCode") IsNot DBNull.Value Then
                If lRow.GetCellValue("InvStatusCode") = Crystal.CLL.EntityStatus.DELTE.ToString OrElse lRow.GetCellValue("InvStatusCode") = Crystal.CLL.EntityStatus.EXTNT.ToString Then
                    grdInvestor.DisplayLayout.Override.ActiveCellAppearance.BackColor = grdInvestor.DisplayLayout.Appearances("InvDelAndExtnct").BackColor 'mclrDelAndExtnct
                    lblnIsRegularCell = False
                End If
            End If
        End If

        'Otherwise, set the backcolor to normal
        If lblnIsRegularCell Then
            grdInvestor.DisplayLayout.Override.ActiveCellAppearance.BackColor = grdInvestor.DisplayLayout.Appearances("GridSelCellBackColor").BackColor 'mclrGridSelCellBackColor
        End If

        Dim lblnIsRegularForeColor As Boolean = True
        'If the selected row is a universal one then set the forecolor to Red
        If lRow.GetCellValue("UniRowIndex").Equals(1) Then
            grdInvestor.DisplayLayout.Override.ActiveRowAppearance.ForeColor = grdInvestor.DisplayLayout.Appearances("InvUniversalInvestor").ForeColor '.BackColor   'Color.Red '
            grdInvestor.DisplayLayout.Override.ActiveCellAppearance.ForeColor = grdInvestor.DisplayLayout.Appearances("InvUniversalInvestor").ForeColor   ' Color.Red
            lblnIsRegularForeColor = False
        End If
        'Otherwise, set the backcolor to normal
        If lblnIsRegularForeColor Then
            grdInvestor.DisplayLayout.Override.ActiveRowAppearance.ForeColor = grdInvestor.DisplayLayout.Appearances("GridSelCellForeColor").ForeColor ' mclrGridSelCellForeColor 
            grdInvestor.DisplayLayout.Override.ActiveCellAppearance.ForeColor = grdInvestor.DisplayLayout.Appearances("GridSelCellForeColor").ForeColor
        End If
    End Sub

    ''' <summary>
    ''' To save the investor mappings
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdInvestor_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles grdInvestor.MouseClick
        If grdInvestor.ActiveRow Is Nothing Then Exit Sub
        SaveInvestorFundMapping(grdInvestor, grdInvestor.ActiveRow.GetCellValue("InvestorID"), 0)
    End Sub

    ''' <summary>
    ''' Dupinder , Create instance of Appereance.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdInvestor_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles grdInvestor.InitializeLayout
        Dim lDelAndExtnctAppereance As Infragistics.Win.Appearance
        Dim lUniversalInvAppereance As Infragistics.Win.Appearance
        Dim lMandAAppereance As Infragistics.Win.Appearance
        Dim lUniMandAAppereance As Infragistics.Win.Appearance
        Dim lGridSelCellForeColor As Infragistics.Win.Appearance
        Dim lGridSelCellBackColor As Infragistics.Win.Appearance
        Try
            If e.Layout.Appearances.Exists("InvDelAndExtnct") = False Then
                lDelAndExtnctAppereance = e.Layout.Appearances.Add("InvDelAndExtnct")
                lDelAndExtnctAppereance.BackColor = mclrDelAndExtnct
            End If

            If e.Layout.Appearances.Exists("InvUniversalInvestor") = False Then
                lUniversalInvAppereance = e.Layout.Appearances.Add("InvUniversalInvestor")
                lUniversalInvAppereance.ForeColor = Color.Red
            End If

            If e.Layout.Appearances.Exists("MandA") = False Then
                lMandAAppereance = e.Layout.Appearances.Add("MandA")
                lMandAAppereance.ForeColor = Color.Blue
            End If

            If e.Layout.Appearances.Exists("UniversalMandA") = False Then
                lUniMandAAppereance = e.Layout.Appearances.Add("UniversalMandA")
                lUniMandAAppereance.ForeColor = Color.Green
            End If

            If e.Layout.Appearances.Exists("GridSelCellForeColor") = False Then
                lGridSelCellForeColor = e.Layout.Appearances.Add("GridSelCellForeColor")
                lGridSelCellForeColor.ForeColor = mclrGridSelCellForeColor
            End If

            If e.Layout.Appearances.Exists("GridSelCellBackColor") = False Then
                lGridSelCellBackColor = e.Layout.Appearances.Add("GridSelCellBackColor")
                lGridSelCellBackColor.BackColor = mclrGridSelCellBackColor
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            lDelAndExtnctAppereance = Nothing
            lUniversalInvAppereance = Nothing
            lMandAAppereance = Nothing
            lUniMandAAppereance = Nothing
            lGridSelCellForeColor = Nothing
            lGridSelCellBackColor = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' To set the fore and back color.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdInvestor_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles grdInvestor.InitializeRow
        If e.ReInitialize = False Then
            'If the Investor is EXTINCT or DELETED, then set the backcolor to ligh pink.
            If e.Row.GetCellValue("InvStatusCode") IsNot DBNull.Value Then
                If e.Row.GetCellValue("InvStatusCode") = Crystal.CLL.EntityStatus.DELTE.ToString OrElse e.Row.GetCellValue("InvStatusCode") = Crystal.CLL.EntityStatus.EXTNT.ToString Then
                    e.Row.Cells("Name").Appearance.BackColor = grdInvestor.DisplayLayout.Appearances("InvDelAndExtnct").BackColor
                    e.Row.Cells("M").Activation = Infragistics.Win.UltraWinGrid.Activation.Disabled
                End If
            End If
            'If the Investor is univesal, then set the forecolor to Red.
            If e.Row.GetCellValue("Property") = mstrUniversal Then
                e.Row.CellAppearance.ForeColor = grdInvestor.DisplayLayout.Appearances("InvUniversalInvestor").ForeColor  'Color.Red
                'If the Investor is Merged/Acquired, then set the forecolor to Blue.
            ElseIf e.Row.GetCellValue("Property") = mstrMergedAcquired Then
                e.Row.Appearance.ForeColor = grdInvestor.DisplayLayout.Appearances("MandA").ForeColor
                'If the Investor is Universal & Merged/Acquired, then set the forecolor to Green.UniversalMandA
            ElseIf e.Row.GetCellValue("Property") = mstrUniversalANDMergedAcquired Then
                e.Row.Appearance.ForeColor = grdInvestor.DisplayLayout.Appearances("UniversalMandA").ForeColor 'Color.Green
            End If
        End If
    End Sub

    Private Sub chkCreateNewFund_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles chkCreateNewFund.KeyPress
        'If e.KeyCode = Keys.Up Then
        '    grdMapData.PerformAction(UltraGridAction.AboveCell)
        '    'Select the down row when user press DOWN arrow on Investor/Fund grid
        'ElseIf e.KeyCode = Keys.Down Then
        '    grdMapData.PerformAction(UltraGridAction.BelowCell)
        'End If
    End Sub

    Private Sub chkCreateNewFund_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles chkCreateNewFund.KeyUp

    End Sub

    ''' <summary>
    ''' Handle the keydown for Map grid
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdInvestor_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles grdInvestor.KeyDown, grdFund.KeyDown, chkCreateNewInv.KeyDown, chkCreateNewFund.KeyDown, chkMarkCustodian.KeyDown
        Dim lblnCanFocusMapData As Boolean = False
        'Select the above row when user press UP arrow on Investor/Fund grid
        If e.Modifiers = Keys.Control Then
            If grdInvestor.Selected.Rows.Count > 1 Then
                If e.KeyCode = Keys.D1 Then
                    For i As Integer = 0 To grdInvestor.Selected.Rows.Count - 1
                        If i = 0 Then Continue For
                        grdInvestor.Selected.Rows(i).Cells("Name").Value = grdInvestor.Selected.Rows(0).Cells("Name").Value
                    Next
                ElseIf e.KeyCode = Keys.D2 Then
                    For i As Integer = 0 To grdInvestor.Selected.Rows.Count - 1
                        If i = 0 Then Continue For
                        grdInvestor.Selected.Rows(i).Cells("Type").Value = grdInvestor.Selected.Rows(0).Cells("Type").Value
                    Next
                ElseIf e.KeyCode = Keys.D3 Then
                    For i As Integer = 0 To grdInvestor.Selected.Rows.Count - 1
                        If i = 0 Then Continue For
                        grdInvestor.Selected.Rows(i).Cells("Style").Value = grdInvestor.Selected.Rows(0).Cells("Style").Value
                    Next
                ElseIf e.KeyCode = Keys.D4 Then
                    For i As Integer = 0 To grdInvestor.Selected.Rows.Count - 1
                        If i = 0 Then Continue For
                        grdInvestor.Selected.Rows(i).Cells("Turnover").Value = grdInvestor.Selected.Rows(0).Cells("Turnover").Value
                    Next
                ElseIf e.KeyCode = Keys.D5 Then
                    For i As Integer = 0 To grdInvestor.Selected.Rows.Count - 1
                        If i = 0 Then Continue For
                        grdInvestor.Selected.Rows(i).Cells("City").Value = grdInvestor.Selected.Rows(0).Cells("City").Value
                    Next
                ElseIf e.KeyCode = Keys.D6 Then
                    For i As Integer = 0 To grdInvestor.Selected.Rows.Count - 1
                        If i = 0 Then Continue For
                        grdInvestor.Selected.Rows(i).Cells("State").Value = grdInvestor.Selected.Rows(0).Cells("State").Value
                    Next
                ElseIf e.KeyCode = Keys.D7 Then
                    For i As Integer = 0 To grdInvestor.Selected.Rows.Count - 1
                        If i = 0 Then Continue For
                        grdInvestor.Selected.Rows(i).Cells("Country").Value = grdInvestor.Selected.Rows(0).Cells("Country").Value
                    Next
                End If
                grdInvestor.UpdateData()
            End If
        ElseIf e.Modifiers = Keys.None Then
            If e.KeyCode = Keys.Up Then
                grdMapData.PerformAction(UltraGridAction.AboveCell)
                'Select the down row when user press DOWN arrow on Investor/Fund grid
            ElseIf e.KeyCode = Keys.Down Then
                grdMapData.PerformAction(UltraGridAction.BelowCell)
            End If
            If e.KeyCode = Keys.Up OrElse e.KeyCode = Keys.Down Then
                If TypeOf sender Is Crystal.CustomControls.CrystalUltraGrid Then
                    If DirectCast(sender, CrystalUltraGrid).DataSource Is Nothing Then
                        lblnCanFocusMapData = True
                    ElseIf DirectCast(sender, CrystalUltraGrid).Rows.Count = 0 Then
                        lblnCanFocusMapData = True
                    End If
                    If lblnCanFocusMapData Then
                        grdMapData.Focus()
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub grdInvestorFundFocus(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSearch.KeyDown, rdContains.KeyDown, rdBeginsWith.KeyDown, chkRetail.KeyDown, chkCustodian.KeyDown, chkCreateNew.KeyDown, btnAdvanceFilter.KeyDown, btnColumnList.KeyDown, btnHelp.KeyDown, rdAll.KeyDown, rdMultiLinks.KeyDown, rdChange.KeyDown, rdConflicts.KeyDown, grdMapData.KeyDown, chkMarkCustodian.KeyDown, chkCreateNewInv.KeyDown, chkCreateNewFund.KeyDown, grdInvestor.KeyDown, grdFund.KeyDown, cmbInvestorField.KeyDown, txtInvSearchChar.KeyDown, cmbFundField.KeyDown, txtFundSearchChar.KeyDown, btnSuggestionGo.KeyDown, txtInvAddress.KeyDown, txtFundAddress.KeyDown, btnAdvancedGo.KeyDown, btnCreateNew.KeyDown, btnFreezeLog.KeyDown, btnMA.KeyDown, btnChangeLog.KeyDown, btnImport.KeyDown, btnSave.KeyDown, btnExit.KeyDown, txtInvestor.KeyDown, txtFund.KeyDown
        If e.Modifiers = Keys.Control Then
            If grdFund.Selected.Rows.Count > 1 Then
                If e.KeyCode = Keys.D1 Then
                    For i As Integer = 0 To grdFund.Selected.Rows.Count - 1
                        If i = 0 Then Continue For
                        grdFund.Selected.Rows(i).Cells("Name").Value = grdFund.Selected.Rows(0).Cells("Name").Value
                    Next
                ElseIf e.KeyCode = Keys.D2 Then
                    'For i As Integer = 0 To grdFund.Selected.Rows.Count - 1
                    '    If i = 0 Then Continue For
                    '    grdFund.Selected.Rows(i).Cells("Type").Value = grdFund.Selected.Rows(0).Cells("Type").Value
                    'Next
                ElseIf e.KeyCode = Keys.D3 Then
                    For i As Integer = 0 To grdFund.Selected.Rows.Count - 1
                        If i = 0 Then Continue For
                        grdFund.Selected.Rows(i).Cells("Style").Value = grdFund.Selected.Rows(0).Cells("Style").Value
                    Next
                ElseIf e.KeyCode = Keys.D4 Then
                    For i As Integer = 0 To grdFund.Selected.Rows.Count - 1
                        If i = 0 Then Continue For
                        grdFund.Selected.Rows(i).Cells("Turnover").Value = grdFund.Selected.Rows(0).Cells("Turnover").Value
                    Next
                ElseIf e.KeyCode = Keys.D5 Then
                    For i As Integer = 0 To grdFund.Selected.Rows.Count - 1
                        If i = 0 Then Continue For
                        grdFund.Selected.Rows(i).Cells("City").Value = grdFund.Selected.Rows(0).Cells("City").Value
                    Next
                ElseIf e.KeyCode = Keys.D6 Then
                    For i As Integer = 0 To grdFund.Selected.Rows.Count - 1
                        If i = 0 Then Continue For
                        grdFund.Selected.Rows(i).Cells("State").Value = grdFund.Selected.Rows(0).Cells("State").Value
                    Next
                ElseIf e.KeyCode = Keys.D7 Then
                    For i As Integer = 0 To grdFund.Selected.Rows.Count - 1
                        If i = 0 Then Continue For
                        grdFund.Selected.Rows(i).Cells("Country").Value = grdFund.Selected.Rows(0).Cells("Country").Value
                    Next
                End If
                grdFund.UpdateData()
            End If
            If e.KeyCode = Keys.K Then
                txtInvestor.Focus()
            ElseIf e.KeyCode = Keys.L Then
                txtFund.Focus()
            ElseIf e.KeyCode = Keys.Z Then
                chkCreateNewInv.Checked = Not chkCreateNewInv.Checked
                ConductCreateNewInvestor()
                grdMapData.UpdateData()
            ElseIf e.KeyCode = Keys.X Then
                chkCreateNewFund.Checked = Not chkCreateNewFund.Checked
                ConductCreateNewFund()
                grdMapData.UpdateData()
            ElseIf e.KeyCode = Keys.N Then
                chkCreateNewInv.Checked = Not chkCreateNewInv.Checked
                ConductCreateNewInvestor()
                chkCreateNewFund.Checked = Not chkCreateNewFund.Checked
                ConductCreateNewFund()
                grdMapData.UpdateData()
            End If
        End If
    End Sub

#End Region

#Region "Funds"

    ''' <summary>
    ''' To set the back and forecolor of the selected cell
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdFund_AfterCellActivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdFund.AfterCellActivate
        Dim lblnIsRegularCell As Boolean = True
        Dim lRow As UltraGridRow
        Dim lblnIsRegularForeColor As Boolean
        Try
            lRow = grdFund.ActiveCell.Row
            'If the selected cell is Investor Name and is Extinct OR Delete then set the backcolor to Pink
            If grdFund.ActiveCell.Column.Header.Caption.Equals("Name") Then
                If lRow.GetCellValue("FundStatusCode") IsNot DBNull.Value Then
                    If lRow.GetCellValue("FundStatusCode") = Crystal.CLL.EntityStatus.DELTE.ToString OrElse lRow.GetCellValue("FundStatusCode") = Crystal.CLL.EntityStatus.EXTNT.ToString Then
                        grdFund.DisplayLayout.Override.ActiveCellAppearance.BackColor = grdFund.DisplayLayout.Appearances("FndDelAndExtnct").BackColor 'mclrDelAndExtnct
                        lblnIsRegularCell = False
                    End If
                End If
            End If
            'Otherwise, set the backcolor to normal
            If lblnIsRegularCell Then
                grdFund.DisplayLayout.Override.ActiveCellAppearance.BackColor = grdFund.DisplayLayout.Appearances("GridSelCellBackColor").BackColor 'mclrGridSelCellBackColor
            End If

            lblnIsRegularForeColor = True
            'If the selected row is a universal one then set the forecolor to Red
            If lRow.GetCellValue("UniRowIndex").Equals(1) Then
                grdFund.DisplayLayout.Override.ActiveRowAppearance.ForeColor = grdFund.DisplayLayout.Appearances("UniversalInvestor").ForeColor
                grdFund.DisplayLayout.Override.ActiveCellAppearance.ForeColor = grdFund.DisplayLayout.Appearances("UniversalInvestor").ForeColor 'Color.Red 'UniversalInvestor
                lblnIsRegularForeColor = False
            End If
            'Otherwise, set the backcolor to normal
            If lblnIsRegularForeColor Then
                grdFund.DisplayLayout.Override.ActiveRowAppearance.ForeColor = grdFund.DisplayLayout.Appearances("GridSelCellForeColor").ForeColor 'mclrGridSelCellForeColor
                grdFund.DisplayLayout.Override.ActiveCellAppearance.ForeColor = grdFund.DisplayLayout.Appearances("GridSelCellForeColor").ForeColor  'mclrGridSelCellForeColor
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            lRow = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' To save the fund mappings
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdFund_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles grdFund.MouseClick
        If grdFund.ActiveRow Is Nothing Then Exit Sub
        SaveInvestorFundMapping(grdFund, 0, grdFund.ActiveRow.GetCellValue("FundID"))
    End Sub

    ''' <summary>
    ''' Dupinder , Create instance of cell apperance.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdFund_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles grdFund.InitializeLayout
        Dim lUniversalInvAppereance As Infragistics.Win.Appearance
        Dim lDelAndExtnctAppereance As Infragistics.Win.Appearance
        Dim lToolTipInfoAppereance As Infragistics.Win.Appearance
        Dim lGridSelCellBackColorAppereance As Infragistics.Win.Appearance
        Dim lGridSelCellBackColor As Infragistics.Win.Appearance
        If e.Layout.Appearances.Exists("UniversalInvestor") = False Then
            lUniversalInvAppereance = e.Layout.Appearances.Add("UniversalInvestor")
            lUniversalInvAppereance.ForeColor = Color.Red
        End If

        If e.Layout.Appearances.Exists("FndDelAndExtnct") = False Then
            lDelAndExtnctAppereance = e.Layout.Appearances.Add("FndDelAndExtnct")
            lDelAndExtnctAppereance.BackColor = mclrDelAndExtnct
        End If

        If e.Layout.Appearances.Exists("ToolTipInfo") = False Then
            lToolTipInfoAppereance = e.Layout.Appearances.Add("ToolTipInfo")
            lToolTipInfoAppereance.ForeColor = Color.FromArgb(246, 214, 115)
        End If

        If e.Layout.Appearances.Exists("GridSelCellForeColor") = False Then
            lGridSelCellBackColorAppereance = e.Layout.Appearances.Add("GridSelCellForeColor")
            lGridSelCellBackColorAppereance.ForeColor = mclrGridSelCellForeColor
        End If

        If e.Layout.Appearances.Exists("GridSelCellBackColor") = False Then
            lGridSelCellBackColor = e.Layout.Appearances.Add("GridSelCellBackColor")
            lGridSelCellBackColor.BackColor = mclrGridSelCellBackColor
        End If
    End Sub

    ''' <summary>
    ''' To set the fore and back color.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub grdFund_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles grdFund.InitializeRow
        If e.ReInitialize = False Then
            'If the fund is EXTINCT or DELETED, then set the backcolor to ligh pink.
            If e.Row.GetCellValue("FundStatusCode") IsNot DBNull.Value Then
                If e.Row.GetCellValue("FundStatusCode") = Crystal.CLL.EntityStatus.DELTE.ToString OrElse e.Row.GetCellValue("FundStatusCode") = Crystal.CLL.EntityStatus.EXTNT.ToString Then
                    e.Row.Cells("Name").Appearance.BackColor = grdFund.DisplayLayout.Appearances("FndDelAndExtnct").BackColor 'mclrDelAndExtnct
                    e.Row.Cells("M").Activation = Infragistics.Win.UltraWinGrid.Activation.Disabled
                End If
            End If
            'If the Investor is univesal, then set the forecolor to Red.
            If e.Row.GetCellValue("Property") = mstrUniversal Then
                e.Row.Appearance = grdFund.DisplayLayout.Appearances("UniversalInvestor") 'Color.Red
            End If
        End If
    End Sub

#End Region

#End Region

#Region "Text Box Events"

    Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
        If MessageManager.GetMessage("EDS_SEARCH") = txtSearch.Text Then Exit Sub
    End Sub

    Private Sub txtSearch_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtSearch.MouseClick
        If MessageManager.GetMessage("EDS_SEARCH") = txtSearch.Text Then
            txtSearch.Text = String.Empty
        End If
    End Sub

    Private Sub txtSearch_Leave(ByVal sender As Object, ByVal e As EventArgs) Handles txtSearch.Leave
        If String.IsNullOrEmpty(txtSearch.Text.Trim()) Then
            SetDefaulSearchText()
        End If
    End Sub

    Private Sub txtInvestorFund_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtInvestor.KeyDown, txtInvAddress.KeyDown, txtFund.KeyDown, txtFundAddress.KeyDown
        If e.KeyCode = Keys.Enter Then
            ConductAdvancedSearch()
        End If
    End Sub

    Private Sub txtInvestor_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInvestor.TextChanged
        If MessageManager.GetMessage("EDS_INVNAME_SEARCH") = txtInvestor.Text Then Exit Sub
    End Sub

    Private Sub txtInvestor_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtInvestor.MouseClick
        If MessageManager.GetMessage("EDS_INVNAME_SEARCH") = txtInvestor.Text Then
            txtInvestor.Text = String.Empty
        End If
    End Sub

    Private Sub txtInvestor_Leave(ByVal sender As Object, ByVal e As EventArgs) Handles txtInvestor.Leave
        If String.IsNullOrEmpty(txtInvestor.Text.Trim()) Then
            SetDefaulInvestorSearchText()
        End If
    End Sub

    Private Sub txtInvAddress_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInvAddress.TextChanged
        If MessageManager.GetMessage("EDS_ADD_SEARCH") = txtInvAddress.Text Then Exit Sub
    End Sub

    Private Sub txtInvAddress_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtInvAddress.MouseClick
        If MessageManager.GetMessage("EDS_ADD_SEARCH") = txtInvAddress.Text Then
            txtInvAddress.Text = String.Empty
        End If
    End Sub

    Private Sub txtInvAddress_Leave(ByVal sender As Object, ByVal e As EventArgs) Handles txtInvAddress.Leave
        If String.IsNullOrEmpty(txtInvAddress.Text.Trim()) Then
            SetDefaulInvAddressSearchText()
        End If
    End Sub

    Private Sub txtFund_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFund.TextChanged
        If MessageManager.GetMessage("EDS_FUNDNAME_SEARCH") = txtFund.Text Then Exit Sub
    End Sub

    Private Sub txtFund_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtFund.MouseClick
        If MessageManager.GetMessage("EDS_FUNDNAME_SEARCH") = txtFund.Text Then
            txtFund.Text = String.Empty
        End If
    End Sub

    Private Sub txtFund_Leave(ByVal sender As Object, ByVal e As EventArgs) Handles txtFund.Leave
        If String.IsNullOrEmpty(txtFund.Text.Trim()) Then
            SetDefaulFundSearchText()
        End If
    End Sub

    Private Sub txtFundAddress_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFundAddress.TextChanged
        If MessageManager.GetMessage("EDS_ADD_SEARCH") = txtFundAddress.Text Then Exit Sub
    End Sub

    Private Sub txtFundAddress_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtFundAddress.MouseClick
        If MessageManager.GetMessage("EDS_ADD_SEARCH") = txtFundAddress.Text Then
            txtFundAddress.Text = String.Empty
        End If
    End Sub

    Private Sub txtFundAddress_Leave(ByVal sender As Object, ByVal e As EventArgs) Handles txtFundAddress.Leave
        If String.IsNullOrEmpty(txtFundAddress.Text.Trim()) Then
            SetDefaulFundAddressSearchText()
        End If
    End Sub

    ''' <summary>
    ''' To do regular search on Map Data grid
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub txtSearch_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSearch.KeyDown
        Dim lblnIsCommonSearch As Boolean
        Dim strAccentedChar As String
        Try
            If e.KeyCode = Keys.Enter Then
                lblnIsCommonSearch = True
                '! is for Special Code search
                If txtSearch.Text.Trim.StartsWith("!") AndAlso IsNumeric(txtSearch.Text.Trim.Substring(1, txtSearch.Text.Length - 1)) Then
                    'Special code row should only be selected (NOT filtered) if its a regular search
                    If grdMapData.Rows.Count <= txtSearch.Text.Trim.TrimStart("!") Then Exit Sub
                    If grdMapData.Rows(txtSearch.Text.Trim.TrimStart("!")).GetCellValue("HasChangeLog") Then
                        lblnIsCommonSearch = False
                        mstrSearchText = txtSearch.Text.Trim.TrimStart("!")
                        'enmSearchTypes = SearchTypes.ChangeLog
                        'AddFilterConditions(False, FilterLogicalOperator.Or)
                        grdMapData.Rows(mstrSearchText).Activated = True
                        grdMapData.Rows(mstrSearchText).Selected = True
                        mstrSearchText = ""
                        'grdMapData.Focus()
                    End If
                End If

                'If it's a common search, then select the next matched cell
                If lblnIsCommonSearch Then
                    mstrSearchText = txtSearch.Text.Trim
                    strAccentedChar = CommonCLL.ReplaceForAccentedChars(mstrSearchText)
                    mstrSearchText = strAccentedChar
                    'grdMapData.Focus()
                    SelectNextPhraseOccurance(grdMapData, grdMapData.ActiveRow.Index, mstrSearchText)
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            lblnIsCommonSearch = Nothing
            strAccentedChar = Nothing
        End Try
    End Sub

    Private Sub txtInvSearchChar_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInvSearchChar.MouseLeave, txtFundSearchChar.MouseLeave
        UltraToolTipManager1.Enabled = False
    End Sub

    Private Sub txtInvSearchChar_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInvSearchChar.MouseEnter
        Dim tipInfo As UltraWinToolTip.UltraToolTipInfo
        Try
            If mblnIsFirstTimeForInvChar Then
                tipInfo = New Infragistics.Win.UltraWinToolTip.UltraToolTipInfo(MessageManager.GetMessage(DBResult.EDS_MATCH_CHAR_COUNT.ToString), ToolTipImage.Info, "Shortcut", DefaultableBoolean.True)
                tipInfo.Appearance.BackColor = Color.FromArgb(246, 214, 115)
                UltraToolTipManager1.Enabled = True
                UltraToolTipManager1.SetUltraToolTip(sender, tipInfo)
                UltraToolTipManager1.ShowToolTip(sender)
                mblnIsFirstTimeForInvChar = False
                Exit Sub
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            tipInfo = Nothing
        End Try
    End Sub

    Private Sub txtFundSearchChar_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFundSearchChar.MouseEnter
        Dim tipInfo As Infragistics.Win.UltraWinToolTip.UltraToolTipInfo
        If mblnIsFirstTimeForFundChar Then
            tipInfo = New Infragistics.Win.UltraWinToolTip.UltraToolTipInfo(MessageManager.GetMessage(DBResult.EDS_MATCH_CHAR_COUNT.ToString), ToolTipImage.Info, "Shortcut", DefaultableBoolean.True)
            tipInfo.Appearance.BackColor = Color.FromArgb(246, 214, 115)
            UltraToolTipManager1.Enabled = True
            UltraToolTipManager1.SetUltraToolTip(sender, tipInfo)
            UltraToolTipManager1.ShowToolTip(sender)
            mblnIsFirstTimeForFundChar = False
            Exit Sub
        End If
    End Sub

    Private Sub txtInvFundChar_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtInvSearchChar.KeyDown, txtFundSearchChar.KeyDown
        If e.KeyCode = Keys.Enter Then
            ConductSuggestionSearch()
        End If
    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles txtInvSearchChar.KeyPress, txtFundSearchChar.KeyPress
        If Not Char.IsControl(e.KeyChar) AndAlso Not Char.IsDigit(e.KeyChar) Then
            e.Handled = True
        End If
    End Sub

#End Region

#Region "Button Events"

    ''' <summary>
    ''' To open Help form
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnHelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHelp.Click
        Dim lfrmHelp As New Help
        lfrmHelp.Show()
        grdMapData.Focus()
        lfrmHelp.BringToFront()
    End Sub

    ''' <summary>
    ''' To do Advanced Search
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnAdvancedGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdvancedGo.Click
        ConductAdvancedSearch()
    End Sub

    ''' <summary>
    ''' To conduct Advanced Filter search
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnAdvanceFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdvanceFilter.Click
        Dim lfrmAdvanceFilter As frmAdvanceFilter = Nothing
        Dim lstrSearchText As String = ""
        Try
            'Show the Advanced Filter form
            lfrmAdvanceFilter = New frmAdvanceFilter
            If lblAdvancedSearchValue.Visible Then
                lfrmAdvanceFilter.mstrInitialSearchText = lblAdvancedSearchValue.Text
            End If
            lfrmAdvanceFilter.ShowDialog()
            If lfrmAdvanceFilter.mblnFromFilter Then
                'If there is a valid Advanced search text, then set the Hide/Show the controls accordingly
                mstrSearchText = lfrmAdvanceFilter.mstrSearchText
                menmAdvancedComparisonOperator = lfrmAdvanceFilter.menmAdvancedComparisonOperator
                txtSearch.Clear()
                mblnIsAdvancedFilter = True
                grdMapData.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False
                lblAdvancedSearchText.Visible = True
                lblAdvancedSearchValue.Visible = True
                lblAdvancedSearchValue.Text = mstrSearchText
                rdFilteredResults.Checked = True
                grdMapData.Focus()
                'If it's special code search
                If mstrSearchText.Trim.StartsWith("!") AndAlso IsNumeric(mstrSearchText.Trim.Substring(1, mstrSearchText.Length - 1)) Then
                    mstrSearchText = mstrSearchText.Trim.TrimStart("!")
                    enmSearchTypes = SearchTypes.ChangeLog
                    AddFilterConditions(False, FilterLogicalOperator.Or)
                    mstrSearchText = ""
                    grdMapData.Focus()
                Else
                    'For other text; Advanced Filter
                    lstrSearchText = CommonCLL.ReplaceRegexMetaChars(mstrSearchText)
                    ConductAdvancedFilter(lstrSearchText, False)
                    SelectNextPhraseOccurance(grdMapData, 0, mstrSearchText)
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            lfrmAdvanceFilter = Nothing
        End Try
    End Sub

    Private Sub btnAdvanceFilter_BackColorChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdvanceFilter.BackColorChanged
        Dim Values As Integer() = New Integer(2) {}
        If CommonCustomControls.IsValidString(StyleManager.GetStyle("ButtonBackColor"), Values) Then
            If btnAdvanceFilter.BackColor <> Color.FromArgb(Values(0), Values(1), Values(2)) Then
                btnAdvanceFilter.BackColor = Color.FromArgb(Values(0), Values(1), Values(2))
            End If
        End If
    End Sub

    ''' <summary>
    ''' To save the incomplete snapshot and exit
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim lintRegularRadio As Int16
        Dim lintAdvancedRadio As Int16
        Dim lintRowNumber As Integer = 0
        Try
            'Save the current settings
            If grdMapData.ActiveRow IsNot Nothing Then
                lintRowNumber = grdMapData.ActiveRow.Index
            End If
            If rdContains.Checked Then
                lintRegularRadio = 1
            Else
                lintRegularRadio = 2
            End If
            If rdAll.Checked Then
                lintAdvancedRadio = 1
            ElseIf rdMultiLinks.Checked Then
                lintAdvancedRadio = 2
            ElseIf rdChange.Checked Then
                lintAdvancedRadio = 3
            ElseIf rdConflicts.Checked Then
                lintAdvancedRadio = 4
            ElseIf rdFilteredResults.Checked Then
                lintAdvancedRadio = 1
            Else
                lintAdvancedRadio = 1
            End If
            lblSaveExit.Visible = True
            Me.Cursor = Cursors.WaitCursor
            pnlImport.Enabled = False
            Application.DoEvents()
            'Save the incompleted snapshot
            If SaveSnapshot(lintRegularRadio, chkRetail.Checked, chkCustodian.Checked, chkCreateNew.Checked, lintAdvancedRadio, lintRowNumber, False) Then
                mblnAnyDataChange = False
                'Dim diaresult As DialogResult = CYMessageBox.Show(MessageManager.GetMessage("EDS_ESOURCE_SAVED"), "Save eSource", CYMessageBox.CustomButtons.OK, CYMessageBox.CYIcon.Warning)

                'ShowMessageBox(DBResult.EDS_ESOURCE_SAVED)
                'Me.Close()
            Else
                ShowMessageBox(DBResult.EDS_ESOURCE_SAVED_FAIL)
            End If

        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            pnlImport.Enabled = True
            lblSaveExit.Visible = False
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    ''' <summary>
    ''' Show the change log
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnChangeLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChangeLog.Click
        Dim lfrmChangeMappingLog As New ChangeMappingLog(mintProjectID)
        lfrmChangeMappingLog.Show()
    End Sub

    ''' <summary>
    ''' To create new Investor/Fund
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnCreateNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateNew.Click
        Dim ldtCreateNewInvestorFund As DataTable = Nothing
        Dim ldtMapData As DataTable = Nothing
        Dim dv As DataView = Nothing
        Dim lfrmCreateInvestorFund As CreateInvestorFund = Nothing
        Dim lintRowCounter As Integer
        Try
            'Filter the create new rows
            ldtMapData = CType(grdMapData.DataSource, DataTable).Copy
            dv = New DataView(ldtMapData)
            dv.RowFilter = "[" + mstrMappedInvName + "] =" + "'" + mstrCreateNew + "' OR [" + mstrMappedFundName + "] ='" + mstrCreateNew + "'"
            ldtCreateNewInvestorFund = dv.ToTable
            If ldtCreateNewInvestorFund.Rows.Count = 0 Then
                ShowMessageBox(DBResult.EDS_MPNG_MARK_CRETE_ROW)
                Exit Sub
            End If
            'Remove the un-necessary columns
            ldtCreateNewInvestorFund.Columns.Remove("LinkCount")
            ldtCreateNewInvestorFund.Columns.Remove("MInvestorTypeID")
            ldtCreateNewInvestorFund.Columns.Remove("UniFullName")
            ldtCreateNewInvestorFund.Columns.Remove("UniInvestorID")
            ldtCreateNewInvestorFund.Columns.Remove("UniFundID")
            ldtCreateNewInvestorFund.Columns.Remove("InvStatusCode")
            ldtCreateNewInvestorFund.Columns.Remove("FundStatusCode")
            'ldtCreateNewInvestorFund.Columns.Remove("ECMapID")
            ldtCreateNewInvestorFund.Columns.Remove("OriginalInvestorID")
            ldtCreateNewInvestorFund.Columns.Remove("OriginalFundID")
            ldtCreateNewInvestorFund.Columns.Remove("EntityID")
            ldtCreateNewInvestorFund.Columns.Remove("ETemplateID")
            ldtCreateNewInvestorFund.Columns.Remove("ClientID")
            ldtCreateNewInvestorFund.Columns.Remove("Full Name")
            ldtCreateNewInvestorFund.Columns.Remove("Doubts")
            ldtCreateNewInvestorFund.Columns.Remove("FilingDateCopy")
            ldtCreateNewInvestorFund.Columns.Remove("HasChangeLog")
            ldtCreateNewInvestorFund.Columns.Remove("UserID")

            lfrmCreateInvestorFund = New CreateInvestorFund(ldtCreateNewInvestorFund)
            'Set the properties
            lfrmCreateInvestorFund.mstrMatchCol3 = mstrMatchCol3
            lfrmCreateInvestorFund.mintSourceTypeID = mintSourceTypeID
            lfrmCreateInvestorFund.mdtColMapping = mdtColMapping
            lfrmCreateInvestorFund.menmSourceTypeCode = menmSourceTypeCode

            lfrmCreateInvestorFund.mintProjectID = mintProjectID
            lfrmCreateInvestorFund.ShowDialog()
            'Investors - If newly created rows are greater than 1, then set the Map Data grid's attributes in the relevant rows.
            If lfrmCreateInvestorFund.mdtNewInvestors.Rows.Count > 0 Then
                For Each lRow As DataRow In lfrmCreateInvestorFund.mdtNewInvestors.Rows
                    lintRowCounter = lRow.Item("RowNumber")
                    If lRow.Item(mstrMappedInvName).Equals(lfrmCreateInvestorFund.mstrUnmapped) Then
                        grdMapData.Rows(lintRowCounter).Cells(mstrMappedInvName).Value = ""
                        Continue For
                    End If

                    SetInvestorRelatedFields(grdMapData.Rows(lintRowCounter), lRow, Nothing, InvestorMappingChangesSource.NewInvCreated)

                Next
                grdMapData.UpdateData()
            End If
            'Funds - If newly created rows are greater than 1, then set the Map Data grid's attributes in the relevant rows.
            If lfrmCreateInvestorFund.mdtNewFunds.Rows.Count > 0 Then
                For Each lRow As DataRow In lfrmCreateInvestorFund.mdtNewFunds.Rows
                    lintRowCounter = lRow.Item("RowNumber")
                    If lRow.Item(mstrMappedFundName).Equals(lfrmCreateInvestorFund.mstrUnmapped) Then
                        grdMapData.Rows(lintRowCounter).Cells(mstrMappedFundName).Value = ""
                        Continue For
                    End If
                    SetFundRelatedFields(grdMapData.Rows(lintRowCounter), lRow, Nothing, FundMappingChangesSource.NewFundCreated)

                    ''Universal InvestorID should be updated only if the Universal InvestorID is nothing
                    'If grdMapData.Rows(lintRowCounter).Cells("UniFundID").Value Is DBNull.Value Then
                    '    grdMapData.Rows(lintRowCounter).Cells("UniFundID").Value = lRow.Item("FundID")
                    'End If
                    'grdMapData.Rows(lintRowCounter).Cells("FundEntityID").Value = lRow.Item("FundEntityID")
                Next
                grdMapData.UpdateData()
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            ldtCreateNewInvestorFund = Nothing
            ldtMapData = Nothing
            dv = Nothing
            lfrmCreateInvestorFund = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Exits from the import eSource
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    ''' <summary>
    ''' To show the column chooser
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnColumnList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnColumnList.Click
        For Each lCol As UltraGridColumn In grdMapData.Rows.Band.Columns
            If marrExcludedFromChooser.Contains(lCol.Header.Caption) Then
                grdMapData.Rows.Band.Columns(lCol.Header.Caption).ExcludeFromColumnChooser = ExcludeFromColumnChooser.True
            Else
                grdMapData.Rows.Band.Columns(lCol.Header.Caption).ExcludeFromColumnChooser = ExcludeFromColumnChooser.False
            End If
        Next

        grdMapData.Rows.Band.Columns(cmbInvestorField.SelectedItem("FieldName")).ExcludeFromColumnChooser = ExcludeFromColumnChooser.True
        grdMapData.Rows.Band.Columns(cmbFundField.SelectedItem("FieldName")).ExcludeFromColumnChooser = ExcludeFromColumnChooser.True
        grdMapData.ShowColumnChooser()
    End Sub

    ''' <summary>
    ''' To show the Import Summary
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnImport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnImport.Click
        Dim ldtMapData As DataTable = Nothing
        Dim lfrmImportSummary As ImportSummary = Nothing
        Dim lstrQuery As String
        Dim larrMapData() As DataRow
        Dim lintDoubtCount As Integer = 0
        Dim lintBothUnmappedCount As Integer = 0
        Dim lintFundMappedCount As Integer = 0
        Dim lintInvestorMappedCount As Integer = 0
        Dim lintBothMappedCount As Integer = 0
        Dim larrExcludeFromDisable() As String = {""}
        Dim larrCreateNewRows() As DataRow = Nothing
        Dim lblnCanOpenCreateNew As Boolean = False
        Try
            ldtMapData = CType(grdMapData.DataSource, DataTable)
            'If there are any 'Create New' then open the Create New form on click of Import
            larrCreateNewRows = ldtMapData.Select("[" + mstrMappedInvName + "] =" + "'" + mstrCreateNew + "' OR [" + mstrMappedFundName + "] ='" + mstrCreateNew + "'")
            If larrCreateNewRows IsNot Nothing Then
                If larrCreateNewRows.Length > 0 Then
                    lblnCanOpenCreateNew = True
                End If
            End If
            If lblnCanOpenCreateNew Then
                btnCreateNew.PerformClick()
            End If
            'Validate Must Change i.e. EXTNT and DELTE
            lstrQuery = "InvStatusCode ='" + Crystal.CLL.EntityStatus.EXTNT.ToString + "' OR InvStatusCode ='" + Crystal.CLL.EntityStatus.DELTE.ToString + "' OR FundStatusCode ='" + Crystal.CLL.EntityStatus.EXTNT.ToString + "' OR FundStatusCode ='" + Crystal.CLL.EntityStatus.DELTE.ToString + "'"
            larrMapData = ldtMapData.Select(lstrQuery)
            If larrMapData.Length > 0 Then
                Me.ShowMessageBox(DBResult.EDS_VALIDATE_MUST_CHNGE)
                Exit Sub
            End If
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            'This code retrieves the records which have duplicated match column values and different mapping provided. This code is not needed now, as such mappings should
            ''be ignored and it's positions should be used.
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            'Validate Doubts
            lstrQuery = "Doubts ='True'"
            larrMapData = ldtMapData.Select(lstrQuery)
            lintDoubtCount = larrMapData.Length

            'Validate Unmapped Investor and Unmapped Funds
            lstrQuery = "InvestorID IS NULL AND FundID IS NULL"
            larrMapData = ldtMapData.Select(lstrQuery)
            lintBothUnmappedCount = larrMapData.Length

            'Validate Unmapped Investor and Mapped Funds
            lstrQuery = "InvestorID IS NULL AND FundID IS NOT NULL"
            larrMapData = ldtMapData.Select(lstrQuery)
            lintFundMappedCount = larrMapData.Length

            'Validate Mapped Investor and Unmapped Funds
            lstrQuery = "InvestorID IS NOT NULL AND FundID IS NULL"
            larrMapData = ldtMapData.Select(lstrQuery)
            lintInvestorMappedCount = larrMapData.Length

            'Count Mapped Investor and Mapped Funds
            lstrQuery = "InvestorID IS NOT NULL AND FundID IS NOT NULL"
            larrMapData = ldtMapData.Select(lstrQuery)
            lintBothMappedCount = larrMapData.Length

            'Show Import Summary
            lfrmImportSummary = New ImportSummary(lintDoubtCount, lintBothUnmappedCount, lintFundMappedCount, lintInvestorMappedCount, lintBothMappedCount)
            lfrmImportSummary.mintClientID = mintClientID
            lfrmImportSummary.mintTemplateID = mintTemplateID
            lfrmImportSummary.mintProjectID = mintProjectID
            lfrmImportSummary.mintListingID = mintListingID
            lfrmImportSummary.mintEntityID = mintEntityID
            lfrmImportSummary.mdtColMapping = mdtColMapping
            lfrmImportSummary.marrMatchCols = marrMatchCols
            lfrmImportSummary.mstrMatchCol1 = mstrMatchCol1
            lfrmImportSummary.mstrMatchCol2 = mstrMatchCol2
            lfrmImportSummary.mstrMatchCol3 = mstrMatchCol3
            lfrmImportSummary.mstrMatchCol4 = mstrMatchCol4
            lfrmImportSummary.mstrMatchCol5 = mstrMatchCol5
            lfrmImportSummary.mstrPosition = mstrPosition
            lfrmImportSummary.mstrMappedInvName = mstrMappedInvName
            lfrmImportSummary.mstrMappedFundName = mstrMappedFundName
            lfrmImportSummary.mstrExcelFundField = mstrExcelFundField
            lfrmImportSummary.mdtMapData = CType(grdMapData.DataSource, DataTable).Copy
            lfrmImportSummary.menmSourceTypeCode = menmSourceTypeCode
            lfrmImportSummary.ShowDialog()

            'If imported successfully, then save the snapshot and disable the controls
            If lfrmImportSummary.mblnIsImportSuccess Then
                lblSaveExit.Visible = True
                mblnIsImportSuccessful = True
                Me.Cursor = Cursors.WaitCursor
                DisableControls(Me.Controls, larrExcludeFromDisable)
                Application.DoEvents()
                SaveSnapshot(1, True, True, True, 1, 0, True)
                mblnAnyDataChange = False
            Else
                'If Record Summary is selected from the Summary form, then filter the records accordingly.
                rdFilteredResults.Checked = True
                If lfrmImportSummary.menmImportSummaryType = ImportSummaryType.Doubt Then
                    enmSearchTypes = SearchTypes.Doubt
                    AddFilterConditions(False, FilterLogicalOperator.Or)
                ElseIf lfrmImportSummary.menmImportSummaryType = ImportSummaryType.BothUnmapped Then
                    enmSearchTypes = SearchTypes.BothUnmapped
                    AddFilterConditions(False, FilterLogicalOperator.Or)
                ElseIf lfrmImportSummary.menmImportSummaryType = ImportSummaryType.FundMapped Then
                    enmSearchTypes = SearchTypes.FundMapped
                    AddFilterConditions(False, FilterLogicalOperator.Or)
                ElseIf lfrmImportSummary.menmImportSummaryType = ImportSummaryType.InvestorMapped Then
                    enmSearchTypes = SearchTypes.InvestorMapped
                    AddFilterConditions(False, FilterLogicalOperator.Or)
                ElseIf lfrmImportSummary.menmImportSummaryType = ImportSummaryType.BothMapped Then
                    enmSearchTypes = SearchTypes.BothMapped
                    AddFilterConditions(False, FilterLogicalOperator.Or)
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            ldtMapData = Nothing
            lfrmImportSummary = Nothing
            larrMapData = Nothing
            lblSaveExit.Visible = False
            Me.Cursor = Cursors.Default
            pnlUltra.Enabled = True
            btnExit.Enabled = True
        End Try
    End Sub

    ''' <summary>
    ''' Conduct suggestion search
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnSuggestionGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuggestionGo.Click
        ConductSuggestionSearch()
    End Sub

#End Region

#Region "Checkbox Events"

    ''' <summary>
    ''' To mark the record as Custodian
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub chkMarkCustodian_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkMarkCustodian.Click
        MarkCustodian()
    End Sub

    ''' <summary>
    ''' To mark an Investor as Create New
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub chkCreateNewInv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCreateNewInv.Click
        ConductCreateNewInvestor()
    End Sub

    Private Sub ConductCreateNewInvestor()
        Dim lblnZeroIsSelectedRow As Boolean
        Try
            If grdMapData.Selected.Rows.Count > 0 OrElse grdMapData.ActiveRow IsNot Nothing Then
                'Select a row through code, if no row is selected.
                lblnZeroIsSelectedRow = False
                If grdMapData.Selected.Rows.Count = 0 Then
                    lblnZeroIsSelectedRow = True
                    grdMapData.Rows(grdMapData.ActiveRow.Index).Selected = True
                End If
                'Mark the rows and attributes to create new
                For Each lRow As UltraGridRow In grdMapData.Selected.Rows
                    SetInvestorRelatedFields(lRow, Nothing, Nothing, InvestorMappingChangesSource.NewInvMarked)
                Next
                'Un-select a row through code, if no row was selected.
                If lblnZeroIsSelectedRow Then
                    grdMapData.Rows(grdMapData.ActiveRow.Index).Selected = False
                End If
                CType(grdMapData.DataSource, DataTable).AcceptChanges()
                grdMapData.Focus()
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            lblnZeroIsSelectedRow = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' To mark an Fund as Create New
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub chkCreateNewFund_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCreateNewFund.Click
        ConductCreateNewFund()
    End Sub

    Private Sub ConductCreateNewFund()
        Dim lblnZeroIsSelectedRow As Boolean
        Try
            If grdMapData.Selected.Rows.Count > 0 OrElse grdMapData.ActiveRow IsNot Nothing Then
                'Select a row through code, if no row is selected.
                lblnZeroIsSelectedRow = False
                If grdMapData.Selected.Rows.Count = 0 Then
                    lblnZeroIsSelectedRow = True
                    grdMapData.Rows(grdMapData.ActiveRow.Index).Selected = True
                End If
                'Mark the rows and attributes to create new
                For Each lRow As UltraGridRow In grdMapData.Selected.Rows
                    SetFundRelatedFields(lRow, Nothing, Nothing, FundMappingChangesSource.NewFundMarked)
                Next
                'Un-select a row through code, if no row was selected.
                If lblnZeroIsSelectedRow Then
                    grdMapData.Rows(grdMapData.ActiveRow.Index).Selected = False
                End If
                CType(grdMapData.DataSource, DataTable).AcceptChanges()
                grdMapData.Focus()
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            lblnZeroIsSelectedRow = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' To hide/show the Create New rows from Map Data
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub chkCreateNew_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkCreateNew.CheckedChanged
        If chkCreateNew.Checked Then
            For Each lRow As UltraGridRow In grdMapData.Rows
                If lRow.GetCellValue(mstrMappedInvName) Is DBNull.Value AndAlso lRow.GetCellValue(mstrMappedFundName) Is DBNull.Value Then Continue For
                If lRow.GetCellValue(mstrMappedInvName).ToString = mstrCreateNew OrElse lRow.GetCellValue(mstrMappedFundName).ToString = mstrCreateNew Then
                    lRow.Hidden = True
                End If
            Next
        Else
            For Each lRow As UltraGridRow In grdMapData.Rows
                If lRow.GetCellValue(mstrMappedInvName) Is DBNull.Value AndAlso lRow.GetCellValue(mstrMappedFundName) Is DBNull.Value Then Continue For
                If lRow.GetCellValue(mstrMappedInvName).ToString = mstrCreateNew OrElse lRow.GetCellValue(mstrMappedFundName).ToString = mstrCreateNew Then
                    lRow.Hidden = False
                End If
            Next
        End If
    End Sub

    ''' <summary>
    ''' To hide/show the Custodian rows from Map Data
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub chkCustodian_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCustodian.CheckedChanged
        If chkCustodian.Checked Then
            For Each lRow As UltraGridRow In grdMapData.Rows
                If lRow.GetCellValue("InvestorID") Is DBNull.Value Then Continue For
                If lRow.GetCellValue("InvestorID") = mintCustodianInvestorID Then
                    lRow.Hidden = True
                End If
            Next
        Else
            For Each lRow As UltraGridRow In grdMapData.Rows
                If lRow.GetCellValue("InvestorID") Is DBNull.Value Then Continue For
                If lRow.GetCellValue("InvestorID") = mintCustodianInvestorID Then
                    lRow.Hidden = False
                End If
            Next
        End If
    End Sub

    ''' <summary>
    ''' To hide/show the Retail rows from Map Data
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub chkRetail_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkRetail.CheckedChanged
        If chkRetail.Checked Then
            For Each lRow As UltraGridRow In grdMapData.Rows
                If lRow.GetCellValue("MInvestorTypeID") Is DBNull.Value Then Continue For
                If lRow.GetCellValue("MInvestorTypeID") = mintRetailMInvTypeID Then
                    lRow.Hidden = True
                End If
            Next
        Else
            For Each lRow As UltraGridRow In grdMapData.Rows
                If lRow.GetCellValue("MInvestorTypeID") Is DBNull.Value Then Continue For
                If lRow.GetCellValue("MInvestorTypeID") = mintRetailMInvTypeID Then
                    lRow.Hidden = False
                End If
            Next
        End If
    End Sub

#End Region

#Region "Radio Events"

    ''' <summary>
    ''' To show all the records in Map Data grid
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub rdAll_MouseClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdAll.MouseClick
        CallAllMapDataRecords()
    End Sub

    Private Sub CallAllMapDataRecords()
        Try
            SetControlsAfterFilterSelection(True)
            mstrSearchText = ""
            For Each lRow As UltraGridRow In grdMapData.Rows
                'Hide custodians if the relevant check box is checked
                If lRow.GetCellValue("InvestorID").Equals(mintCustodianInvestorID) Then
                    lRow.Hidden = chkCustodian.Checked
                    'Hide Retailers if the relevant check box is checked
                ElseIf lRow.GetCellValue("MInvestorTypeID").Equals(mintRetailMInvTypeID) Then
                    lRow.Hidden = chkRetail.Checked
                    'Hide Create New if the relevant check box is checked
                ElseIf lRow.GetCellValue(mstrMappedInvName).Equals(mstrCreateNew) OrElse lRow.GetCellValue(mstrMappedFundName).Equals(mstrCreateNew) Then
                    lRow.Hidden = chkCreateNew.Checked
                Else
                    lRow.Hidden = False
                    'If the Advanced Filter is true, which is going to be set to false, then set rows' formatting to normal.
                    If mblnIsAdvancedFilter Then
                        SetAdvancedSearchFormattingToNormal(lRow)
                    End If
                End If
            Next
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        End Try
    End Sub

    ''' <summary>
    ''' To show all the records whose mapped funds are linked with multiple investors
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub rdMultiLinks_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdMultiLinks.CheckedChanged
        Dim lintFirstEligibleRowIndex As Integer
        Try
            If rdMultiLinks.Checked Then
                SetControlsAfterFilterSelection(False)
                lintFirstEligibleRowIndex = -1
                For Each lRow As UltraGridRow In grdMapData.Rows
                    If lRow.GetCellValue("LinkCount") Is DBNull.Value Then
                        lRow.Hidden = True
                        Continue For
                    End If
                    If lRow.GetCellValue("LinkCount") >= 2 Then
                        If lintFirstEligibleRowIndex = -1 Then
                            lintFirstEligibleRowIndex = lRow.Index
                        End If
                        lRow.Hidden = False
                    Else
                        lRow.Hidden = True
                    End If
                    If grdMapData.ActiveRow IsNot Nothing Then
                        If mblnIsAdvancedFilter AndAlso lRow.IsFilteredOut = False Then
                            SetAdvancedSearchFormattingToNormal(lRow)
                        End If
                    End If
                Next
                'Select/Activate the first available row
                If grdMapData.ActiveRow IsNot Nothing Then
                    If grdMapData.ActiveRow.Hidden AndAlso lintFirstEligibleRowIndex <> -1 Then
                        grdMapData.Rows(lintFirstEligibleRowIndex).Activated = True
                    End If
                End If
                'Set the Advanced Filter to false
                If mblnIsAdvancedFilter Then
                    mblnIsAdvancedFilter = False
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        End Try
    End Sub

    ''' <summary>
    ''' To show all the records where Status is Extinct Or Delete
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub rdChange_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdChange.CheckedChanged
        Dim lintFirstEligibleRowIndex As Integer
        Try
            If rdChange.Checked Then
                SetControlsAfterFilterSelection(False)
                lintFirstEligibleRowIndex = -1
                For Each lRow As UltraGridRow In grdMapData.Rows
                    If lRow.GetCellValue("InvStatusCode").Equals(Crystal.CLL.EntityStatus.EXTNT.ToString) OrElse lRow.GetCellValue("InvStatusCode").Equals(Crystal.CLL.EntityStatus.DELTE.ToString) OrElse _
                        lRow.GetCellValue("FundStatusCode").Equals(Crystal.CLL.EntityStatus.EXTNT.ToString) OrElse lRow.GetCellValue("FundStatusCode").Equals(Crystal.CLL.EntityStatus.DELTE.ToString) Then
                        If lintFirstEligibleRowIndex = -1 Then
                            lintFirstEligibleRowIndex = lRow.Index
                        End If
                        lRow.Hidden = False
                    Else
                        lRow.Hidden = True
                    End If
                    If mblnIsAdvancedFilter AndAlso lRow.IsFilteredOut = False Then
                        SetAdvancedSearchFormattingToNormal(lRow)
                    End If
                Next
                If grdMapData.ActiveRow IsNot Nothing Then
                    If grdMapData.ActiveRow.Hidden AndAlso lintFirstEligibleRowIndex <> -1 Then
                        grdMapData.Rows(lintFirstEligibleRowIndex).Activated = True
                    End If
                End If
                If mblnIsAdvancedFilter Then
                    mblnIsAdvancedFilter = False
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        End Try
    End Sub

    ''' <summary>
    ''' To show all the records where Universal Mapping does not match with Current Mapping
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub rdConflicts_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdConflicts.CheckedChanged
        Dim lintFirstEligibleRowIndex As Integer
        Try
            If rdConflicts.Checked Then
                SetControlsAfterFilterSelection(False)
                lintFirstEligibleRowIndex = -1
                For Each lRow As UltraGridRow In grdMapData.Rows
                    If (lRow.GetCellValue("InvestorID").Equals(lRow.GetCellValue("UniInvestorID")) = False AndAlso lRow.GetCellValue("UniInvestorID") IsNot DBNull.Value) OrElse (lRow.GetCellValue("FundID").Equals(lRow.GetCellValue("UniFundID")) = False AndAlso lRow.GetCellValue("UniFundID") IsNot DBNull.Value) Then
                        If lintFirstEligibleRowIndex = -1 Then
                            lintFirstEligibleRowIndex = lRow.Index
                        End If
                        lRow.Hidden = False
                    Else
                        lRow.Hidden = True
                    End If
                    If mblnIsAdvancedFilter AndAlso lRow.IsFilteredOut = False Then
                        SetAdvancedSearchFormattingToNormal(lRow)
                    End If
                Next
                If grdMapData.ActiveRow IsNot Nothing Then
                    If grdMapData.ActiveRow.Hidden AndAlso lintFirstEligibleRowIndex <> -1 Then
                        grdMapData.Rows(lintFirstEligibleRowIndex).Activated = True
                    End If
                End If
                If mblnIsAdvancedFilter Then
                    mblnIsAdvancedFilter = False
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        End Try
    End Sub

#End Region

#Region "Menu Item Events"

    ''' <summary>
    ''' To restore original investor
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub mnuRestoreOriginalInvestor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuRestoreOriginalInvestor.Click
        RestoreOriginalMappings("OriginalInvestorID", "InvestorID", True, grdInvestor)
    End Sub

    ''' <summary>
    ''' To restore original Fund
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub mnuRestoreOriginalFund_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuRestoreOriginalFund.Click
        RestoreOriginalMappings("OriginalFundID", "FundID", False, grdFund)
    End Sub

#End Region

#Region "Excel Exporter"
    Private Sub UltraGridExcelExporter1_BeginExport(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.ExcelExport.BeginExportEventArgs) Handles UltraGridExcelExporter1.BeginExport
        'For Each lCol As UltraGridColumn In grdMapData.DisplayLayout.Bands(0).Columns
        '    If lCol.Hidden Then
        '        lCol.Hidden = False
        '    End If
        'Next

        'For Each lRow As UltraGridRow In grdMapData.Rows
        '    If lRow.Hidden Then
        '        lRow.Hidden = False
        '    End If
        'Next
    End Sub
#End Region

#Region "Ultragrid Export Events"

    ''' <summary>
    ''' To unhide all columns before exporting so that they can be available in the exported excel file.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub UltraGridExcelExporter1_ExportStarted(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.ExcelExport.ExportStartedEventArgs) Handles UltraGridExcelExporter1.ExportStarted
        For Each column In e.Layout.Bands(0).Columns
            column.Hidden = False
        Next
    End Sub

#End Region

#End Region

#Region "Procedures"

    ''' <summary>
    ''' To get data from Excel
    ''' </summary>
    ''' <param name="isColumDupliacte">To determine if only clone is required</param>
    ''' <param name="dtInvestor">To store the excel data</param>
    ''' <param name="pstrSnapshotFilePath">The path of the snapshot file</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetDataFromExcel(ByVal isColumDupliacte As Boolean, ByRef dtInvestor As DataTable, ByVal pstrSnapshotFilePath As String) As DataTable
        'Create the temporary table to store data
        Dim internalWorkBook As Infragistics.Documents.Excel.Workbook = Nothing
        Dim myDataColumn As DataColumn
        Dim myDataRow As DataRow
        Dim lstrSheetName As String
        Dim minCellRow As Integer
        Dim maxCellRow As Integer
        Dim minCellColumn As Integer
        Dim maxCellColumn As Integer
        Dim columnName As String
        Dim larrPositionCol() As DataRow
        Dim lstrPositionMapCol As String = ""
        'Dim lrow As Integer = 0
        'Dim lcol As Integer = 0
        Try

            internalWorkBook = Infragistics.Documents.Excel.Workbook.Load(pstrSnapshotFilePath, False)

            lstrSheetName = internalWorkBook.Worksheets(0).Name
            'MIN/MAX Values used to frame the working size of the Excel data to be imported.
            minCellRow = Int32.MaxValue
            maxCellRow = Int32.MinValue
            minCellColumn = Int32.MaxValue
            maxCellColumn = Int32.MinValue

            'To set the min and max column/row
            For Each row As Infragistics.Documents.Excel.WorksheetRow In internalWorkBook.Worksheets(lstrSheetName).Rows
                For Each cell As Infragistics.Documents.Excel.WorksheetCell In row.Cells
                    'lsheet.Rows(lintRowCounter).GetCellValue(cell.ColumnIndex)
                    If row.GetCellValue(cell.ColumnIndex) IsNot Nothing Then
                        'Logic For Determining the Range of Rows/Columns in the Excel File.
                        minCellRow = Math.Min(minCellRow, cell.RowIndex)
                        maxCellRow = Math.Max(maxCellRow, cell.RowIndex)
                        minCellColumn = Math.Min(minCellColumn, cell.ColumnIndex)
                        maxCellColumn = Math.Max(maxCellColumn, cell.ColumnIndex)
                    End If
                Next
            Next

            If isColumDupliacte = True Then
                For i As Integer = minCellColumn To maxCellColumn
                    'Get the column name
                    columnName = internalWorkBook.Worksheets(lstrSheetName).Rows(minCellRow).Cells(i).Value.ToString().Trim
                    'The export that was demonstrated earlier utilizes the first row
                    'for the column header.  We can now use that to give column names.
                    myDataColumn = New DataColumn(columnName)
                    dtInvestor.Columns.Add(myDataColumn)
                Next
            Else

                'Get the index of the Position column
                larrPositionCol = mdtColMapping.Select("DBFieldName ='Position'")
                If larrPositionCol.Length = 1 Then
                    lstrPositionMapCol = larrPositionCol(0).Item("Map Field").ToString
                End If

                columnName = String.Empty
                For i As Integer = minCellColumn To maxCellColumn
                    columnName = internalWorkBook.Worksheets(lstrSheetName).Rows(minCellRow).GetCellValue(internalWorkBook.Worksheets(lstrSheetName).Rows(minCellRow).Cells(i).ColumnIndex).ToString().Trim
                    'Dim columnName As String = internalWorkBook.Worksheets(lstrSheetName).Rows(minCellRow).Cells(i).Value.ToString()
                    'The export that was demonstrated earlier utilizes the first row
                    'for the column header.  We can now use that to give column names.
                    If columnName.Equals(lstrPositionMapCol) Then
                        myDataColumn = New DataColumn(columnName, GetType(Int64))
                    ElseIf columnName.Equals("EntityID") OrElse columnName.Equals("InvestorID") OrElse columnName.Equals("FundID") OrElse columnName.Equals("OriginalInvestorID") _
                        OrElse columnName.Equals("OriginalFundID") OrElse columnName.Equals("UserID") OrElse columnName.Equals("LinkCount") OrElse columnName.Equals("UniFundID") _
                        OrElse columnName.Equals("UniInvestorID") Then
                        myDataColumn = New DataColumn(columnName, GetType(Integer))
                    ElseIf columnName.Equals("Doubts") OrElse columnName.Equals("HasChangeLog") Then
                        myDataColumn = New DataColumn(columnName, GetType(Boolean))
                    ElseIf columnName.Equals("MInvestorTypeID") Then
                        myDataColumn = New DataColumn(columnName, GetType(Int16))
                    Else
                        myDataColumn = New DataColumn(columnName)
                    End If
                    dtInvestor.Columns.Add(myDataColumn)
                Next

                For rowIndex As Integer = minCellRow + 1 To maxCellRow
                    'Create a new DataRow
                    myDataRow = dtInvestor.NewRow()
                    'lrow = rowIndex
                    'Loop through the columns and associate the value to each cell
                    For columnIndex As Integer = minCellColumn To maxCellColumn
                        'lcol = columnIndex
                        If internalWorkBook.Worksheets(lstrSheetName).Rows(rowIndex).GetCellValue(internalWorkBook.Worksheets(lstrSheetName).Rows(rowIndex).Cells(columnIndex).ColumnIndex) Is Nothing Then
                            myDataRow(columnIndex) = DBNull.Value
                        ElseIf internalWorkBook.Worksheets(lstrSheetName).Rows(rowIndex).GetCellValue(internalWorkBook.Worksheets(lstrSheetName).Rows(rowIndex).Cells(columnIndex).ColumnIndex).Equals("") Then
                            myDataRow(columnIndex) = DBNull.Value
                        Else
                            myDataRow(columnIndex) = internalWorkBook.Worksheets(lstrSheetName).Rows(rowIndex).GetCellValue(internalWorkBook.Worksheets(lstrSheetName).Rows(rowIndex).Cells(columnIndex).ColumnIndex)
                        End If
                    Next
                    'Add The Row to a DataTable
                    dtInvestor.Rows.Add(myDataRow)
                Next
            End If
            Return dtInvestor
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
            Return Nothing
        Finally
            internalWorkBook = Nothing
        End Try
    End Function

    Public Sub SetDefaulSearchText()
        txtSearch.Text = MessageManager.GetMessage("EDS_SEARCH")
    End Sub

    Public Sub SetDefaulInvestorSearchText()
        txtInvestor.Text = MessageManager.GetMessage("EDS_INVNAME_SEARCH")
    End Sub

    Public Sub SetDefaulFundSearchText()
        txtFund.Text = MessageManager.GetMessage("EDS_FUNDNAME_SEARCH")
    End Sub

    Public Sub SetDefaulInvAddressSearchText()
        txtInvAddress.Text = MessageManager.GetMessage("EDS_ADD_SEARCH")
    End Sub

    Public Sub SetDefaulFundAddressSearchText()
        txtFundAddress.Text = MessageManager.GetMessage("EDS_ADD_SEARCH")
    End Sub

    ''' <summary>
    ''' To load the data in the grid
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub LoadGridData()
        Dim sqlBulkCopy As System.Data.SqlClient.SqlBulkCopy = Nothing
        Dim ldtMappings As DataTable = Nothing
        Dim ldtOtherAttributes As DataTable = Nothing
        Dim lintRowCounter As Integer
        Dim lintFullNameIndex As Integer
        Dim larrMappedCol() As DataRow

        Try
            'Check if Client Mapping and Universal mappings exist.
            'Get the CustodianInvestorID, Custodian Investor, Retail MasterInvestorTypeID
            mclsImporteSourceManager.GetUniClientMappingStatus(mintTemplateID, mintClientID, mblnIsClientMappingExists, mblnIsUniversalMappingExists, mintCustodianInvestorID, mstrCustodianInvestor, mintRetailMInvTypeID, mintEntityID, mintProjectID)
            'Check what kind of mapping to be used i.e. Client, Excel, Universal OR Manual
            If mblnIsClientMappingExists Then
                enmMappingType = MappingType.Client
            ElseIf mstrExcelInvestorField.Equals("") = False OrElse mstrExcelFundField.Equals("") = False Then
                enmMappingType = MappingType.Excel
            ElseIf mblnIsUniversalMappingExists Then
                enmMappingType = MappingType.Universal
            Else
                enmMappingType = MappingType.Manual
            End If

            'If the snapshot type is Incomplete Or Complete, then bind the grid with excel file data directly
            If menmSnapshotType = SnapshotType.Incomplete OrElse menmSnapshotType = SnapshotType.Complete Then
                'Clear the selected entity's data from the table 
                CommonManager.ClearBulkStagingTable("EDS_BulkOtherAttributesForSnapshot", mintEntityID)
                sqlBulkCopy = New System.Data.SqlClient.SqlBulkCopy(mstrConnectionstring)
                'Define column mappings to specify the columnn/data to be saved in staging table
                sqlBulkCopy.DestinationTableName = "EDS_BulkOtherAttributesForSnapshot"
                sqlBulkCopy.ColumnMappings.Add("EntityID", "EntityID")
                sqlBulkCopy.ColumnMappings.Add("InvestorID", "InvestorID")
                sqlBulkCopy.ColumnMappings.Add("FundID", "FundID")

                sqlBulkCopy.WriteToServer(mdtExcelData)
                sqlBulkCopy.Close()
                sqlBulkCopy = Nothing

                ldtOtherAttributes = New DataTable
                ldtOtherAttributes = mclsImporteSourceManager.GetOtherAttributesForSnapshot(mintEntityID)

                lintRowCounter = 0
                While lintRowCounter < ldtOtherAttributes.Rows.Count
                    mdtExcelData.Rows(lintRowCounter).Item("MInvestorTypeID") = ldtOtherAttributes.Rows(lintRowCounter).Item("MInvestorTypeID")
                    mdtExcelData.Rows(lintRowCounter).Item("InvStatusCode") = ldtOtherAttributes.Rows(lintRowCounter).Item("InvStatusCode")
                    mdtExcelData.Rows(lintRowCounter).Item("FundStatusCode") = ldtOtherAttributes.Rows(lintRowCounter).Item("FundStatusCode")
                    lintRowCounter += 1
                End While

                grdMapData.DataSource = mdtExcelData
            Else
                'Mapping Type is not Manual; i.e. Excel, Client OR Universal, then insert the excel file data in staging table for bulk import
                If enmMappingType <> MappingType.Manual Then
                    'Clear the selected entity's data from the table 
                    CommonManager.ClearBulkStagingTable("EDS_BulkESourceMapping", mintEntityID)
                    sqlBulkCopy = New System.Data.SqlClient.SqlBulkCopy(mstrConnectionstring)
                    'Define column mappings to specify the columnn/data to be saved in staging table
                    sqlBulkCopy.DestinationTableName = "EDS_BulkESourceMapping"
                    sqlBulkCopy.ColumnMappings.Add("EntityID", "EntityID")
                    sqlBulkCopy.ColumnMappings.Add("ETemplateID", "ETemplateID")
                    sqlBulkCopy.ColumnMappings.Add("ClientID", "ClientID")
                    sqlBulkCopy.ColumnMappings.Add("RowNumber", "RowNumber")

                    Dim lstrQuery As String
                    Dim larrDBColCol() As DataRow

                    For Each lstrMatch As String In marrMatchCols
                        'Define the column mapping for match columns
                        lstrQuery = "[Map Field] ='" + lstrMatch + "'"
                        larrDBColCol = mdtColMapping.Select(lstrQuery)
                        If larrDBColCol.Length = 1 Then
                            If larrDBColCol(0).Item("DBFieldName").ToString <> "" Then
                                'For Public
                                If menmSourceTypeCode = SourceTypeCode.PBC Then
                                    sqlBulkCopy.ColumnMappings.Add(lstrMatch, larrDBColCol(0).Item("PublicMatch"))
                                Else
                                    'For Others
                                    sqlBulkCopy.ColumnMappings.Add(lstrMatch, larrDBColCol(0).Item("DBFieldName"))
                                End If
                            End If
                        End If
                    Next

                    'If the Mapping Type is Excel, then selected investor field should be searched, likewise fund
                    If enmMappingType = MappingType.Excel Then
                        sqlBulkCopy.ColumnMappings.Add(mstrSelectedInvestorField, "MappedInvestorName")
                        sqlBulkCopy.ColumnMappings.Add(mstrSelectedFundField, "MappedFundName")
                    End If

                    sqlBulkCopy.WriteToServer(mdtExcelData)
                    sqlBulkCopy.Close()
                    sqlBulkCopy = Nothing
                End If

                'Add columns in the ExcelData datatable
                mdtExcelData.Columns.Add("InvestorID", GetType(Integer))
                mdtExcelData.Columns("InvestorID").SetOrdinal(0)

                mdtExcelData.Columns.Add("FundID", GetType(Integer))
                mdtExcelData.Columns("FundID").SetOrdinal(1)

                mdtExcelData.Columns.Add(mstrMappedInvName, GetType(String))
                mdtExcelData.Columns(mstrMappedInvName).SetOrdinal(0)

                mdtExcelData.Columns.Add(mstrMappedFundName, GetType(String))
                mdtExcelData.Columns(mstrMappedFundName).SetOrdinal(1)

                mdtExcelData.Columns.Add("OriginalInvestorID", GetType(Integer))
                mdtExcelData.Columns("OriginalInvestorID").SetOrdinal(0)

                mdtExcelData.Columns.Add("OriginalFundID", GetType(Integer))
                mdtExcelData.Columns("OriginalFundID").SetOrdinal(1)

                mdtExcelData.Columns.Add("Full Name", GetType(String))
                mdtExcelData.Columns("Full Name").SetOrdinal(0)

                mdtExcelData.Columns.Add("UserID", GetType(Integer))
                mdtExcelData.Columns("UserID").SetOrdinal(0)

                mdtExcelData.Columns.Add("InvStatusCode", GetType(String))
                mdtExcelData.Columns("InvStatusCode").SetOrdinal(0)

                mdtExcelData.Columns.Add("FundStatusCode", GetType(String))
                mdtExcelData.Columns("FundStatusCode").SetOrdinal(0)

                mdtExcelData.Columns.Add("Doubts", GetType(Boolean))
                mdtExcelData.Columns("Doubts").SetOrdinal(0)

                mdtExcelData.Columns.Add("LinkCount", GetType(Integer))
                mdtExcelData.Columns("LinkCount").SetOrdinal(0)

                mdtExcelData.Columns.Add("UniFundID", GetType(Integer))
                mdtExcelData.Columns("UniFundID").SetOrdinal(0)

                mdtExcelData.Columns.Add("UniInvestorID", GetType(Integer))
                mdtExcelData.Columns("UniInvestorID").SetOrdinal(0)

                mdtExcelData.Columns.Add("UniFullName", GetType(String))
                mdtExcelData.Columns("UniFullName").SetOrdinal(0)

                mdtExcelData.Columns.Add("MInvestorTypeID", GetType(Int16))
                mdtExcelData.Columns("MInvestorTypeID").SetOrdinal(0)

                mdtExcelData.Columns.Add("HasChangeLog", GetType(Boolean))
                mdtExcelData.Columns("HasChangeLog").SetOrdinal(0)

                mdtExcelData.Columns.Add("InvEntityID", GetType(String))
                mdtExcelData.Columns("InvEntityID").SetOrdinal(0)

                mdtExcelData.Columns.Add("FundEntityID", GetType(String))
                mdtExcelData.Columns("FundEntityID").SetOrdinal(0)

                ldtMappings = New DataTable

                'If MappingType is manual, then set the Doubt and LinkCount only
                If enmMappingType = MappingType.Manual Then
                    While lintRowCounter < mdtExcelData.Rows.Count
                        mdtExcelData.Rows(lintRowCounter).Item("Doubts") = False
                        mdtExcelData.Rows(lintRowCounter).Item("LinkCount") = 0
                        lintRowCounter += 1
                    End While
                Else
                    'Otherwise, get the saved/excelmappings 
                    ldtMappings = mclsImporteSourceManager.GetMappings(mintEntityID, mintTemplateID, mintClientID, enmMappingType, CommonCLL.UserID, mintSourceTypeID)
                    While lintRowCounter < ldtMappings.Rows.Count
                        'If mapping type is universal, then the mapped Investor and Fund will be the universal ones
                        If enmMappingType = MappingType.Universal Then
                            mdtExcelData.Rows(lintRowCounter).Item("InvestorID") = ldtMappings.Rows(lintRowCounter).Item("UniInvestorID")
                            mdtExcelData.Rows(lintRowCounter).Item("FundID") = ldtMappings.Rows(lintRowCounter).Item("UniFundID")
                        Else
                            'Else use the Client Mappings
                            mdtExcelData.Rows(lintRowCounter).Item("InvestorID") = ldtMappings.Rows(lintRowCounter).Item("OriginalInvestorID")
                            mdtExcelData.Rows(lintRowCounter).Item("FundID") = ldtMappings.Rows(lintRowCounter).Item("OriginalFundID")
                        End If
                        mdtExcelData.Rows(lintRowCounter).Item("OriginalInvestorID") = ldtMappings.Rows(lintRowCounter).Item("OriginalInvestorID")
                        mdtExcelData.Rows(lintRowCounter).Item("OriginalFundID") = ldtMappings.Rows(lintRowCounter).Item("OriginalFundID")
                        mdtExcelData.Rows(lintRowCounter).Item("InvStatusCode") = ldtMappings.Rows(lintRowCounter).Item("InvStatusCode")
                        mdtExcelData.Rows(lintRowCounter).Item("FundStatusCode") = ldtMappings.Rows(lintRowCounter).Item("FundStatusCode")
                        If mdtExcelData.Rows(lintRowCounter).Item("UserID") Is DBNull.Value Then
                            mdtExcelData.Rows(lintRowCounter).Item("UserID") = CommonCLL.UserID
                        End If
                        mdtExcelData.Rows(lintRowCounter).Item("Full Name") = ldtMappings.Rows(lintRowCounter).Item("Full Name")
                        mdtExcelData.Rows(lintRowCounter).Item("UniFullName") = ldtMappings.Rows(lintRowCounter).Item("Full Name")
                        mdtExcelData.Rows(lintRowCounter).Item("LinkCount") = ldtMappings.Rows(lintRowCounter).Item("LinkCount")
                        mdtExcelData.Rows(lintRowCounter).Item("Doubts") = False
                        mdtExcelData.Rows(lintRowCounter).Item("Mapped Inv. Name") = ldtMappings.Rows(lintRowCounter).Item("Mapped Inv. Name")
                        mdtExcelData.Rows(lintRowCounter).Item("Mapped Fund Name") = ldtMappings.Rows(lintRowCounter).Item("Mapped Fund Name")
                        mdtExcelData.Rows(lintRowCounter).Item("UniInvestorID") = ldtMappings.Rows(lintRowCounter).Item("UniInvestorID")
                        mdtExcelData.Rows(lintRowCounter).Item("UniFundID") = ldtMappings.Rows(lintRowCounter).Item("UniFundID")
                        mdtExcelData.Rows(lintRowCounter).Item("MInvestorTypeID") = ldtMappings.Rows(lintRowCounter).Item("MInvestorTypeID")
                        mdtExcelData.Rows(lintRowCounter).Item("HasChangeLog") = ldtMappings.Rows(lintRowCounter).Item("HasChangeLog")
                        mdtExcelData.Rows(lintRowCounter).Item("InvEntityID") = ldtMappings.Rows(lintRowCounter).Item("InvEntityID")
                        mdtExcelData.Rows(lintRowCounter).Item("FundEntityID") = ldtMappings.Rows(lintRowCounter).Item("FundEntityID")
                        lintRowCounter += 1
                    End While
                End If
                'Set column indexes/order
                lintFullNameIndex = mdtExcelData.Columns("Full Name").Ordinal
                mdtExcelData.Columns(mstrPosition).SetOrdinal(lintFullNameIndex + 1)
                mdtExcelData.Columns(mstrMappedInvName).SetOrdinal(lintFullNameIndex + 2)
                If menmSourceTypeCode = SourceTypeCode.PBC Then
                    mdtExcelData.Columns(mstrMatchCol3).SetOrdinal(lintFullNameIndex + 3)
                    mdtExcelData.Columns(mstrMappedFundName).SetOrdinal(lintFullNameIndex + 4)
                    mdtExcelData.Columns(mstrMatchCol4).SetOrdinal(lintFullNameIndex + 5)
                    larrMappedCol = mdtColMapping.Select("DBFieldName ='Style'")
                    If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                        mdtExcelData.Columns(larrMappedCol(0).Item("Map Field").ToString).SetOrdinal(lintFullNameIndex + 6)
                    End If
                    larrMappedCol = mdtColMapping.Select("DBFieldName ='City'")
                    If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                        mdtExcelData.Columns(larrMappedCol(0).Item("Map Field").ToString).SetOrdinal(lintFullNameIndex + 7)
                    End If
                    larrMappedCol = mdtColMapping.Select("DBFieldName ='Country'")
                    If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                        mdtExcelData.Columns(larrMappedCol(0).Item("Map Field").ToString).SetOrdinal(lintFullNameIndex + 8)
                    End If
                    larrMappedCol = mdtColMapping.Select("DBFieldName ='State'")
                    If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                        mdtExcelData.Columns(larrMappedCol(0).Item("Map Field").ToString).SetOrdinal(lintFullNameIndex + 9)
                    End If
                    larrMappedCol = mdtColMapping.Select("DBFieldName ='Turnover'")
                    If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                        mdtExcelData.Columns(larrMappedCol(0).Item("Map Field").ToString).SetOrdinal(lintFullNameIndex + 10)
                    End If
                    larrMappedCol = mdtColMapping.Select("DBFieldName ='InvEntityID'")
                    If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                        mdtExcelData.Columns(larrMappedCol(0).Item("Map Field").ToString).SetOrdinal(lintFullNameIndex + 11)
                    End If
                    larrMappedCol = mdtColMapping.Select("DBFieldName ='FundEntityID'")
                    If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                        mdtExcelData.Columns(larrMappedCol(0).Item("Map Field").ToString).SetOrdinal(lintFullNameIndex + 12)
                    End If
                Else
                    mdtExcelData.Columns(mstrMappedFundName).SetOrdinal(lintFullNameIndex + 3)
                End If
                grdMapData.DataSource = mdtExcelData
            End If
            mintInvStatusCodeIndex = mdtExcelData.Columns("InvStatusCode").Ordinal
            mintFundStatusCodeIndex = mdtExcelData.Columns("FundStatusCode").Ordinal
            mintLinkCountIndex = mdtExcelData.Columns("LinkCount").Ordinal
            SetGridProperties()
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            ManageScreenStatus(mintEntityID, mintProjectID, CommonCLL.UserID, False, False, False)
            'ManageScreenStatus(mintEntityID, False, CommonCLL.UserID)
            CommonManager.ClearBulkStagingTable("EDS_BulkESourceMapping", mintEntityID)
            CommonManager.ClearBulkStagingTable("EDS_BulkOtherAttributesForSnapshot", mintEntityID)
            sqlBulkCopy = Nothing
            ldtMappings = Nothing
            ldtOtherAttributes = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Hide the Map Data columns
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SetGridProperties()
        'If the EDS is incomplated or Completed then load the mapping screen through snapshot
        If menmSnapshotType = SnapshotType.NoSnapshot Then
            grdMapData.Rows.Band.Columns("Full Name").Hidden = True
        End If
        grdMapData.Rows.Band.Columns("FundEntityID").Hidden = True
        grdMapData.Rows.Band.Columns("InvEntityID").Hidden = True
        grdMapData.Rows.Band.Columns("HasChangeLog").Hidden = True
        grdMapData.Rows.Band.Columns("UniInvestorID").Hidden = True
        grdMapData.Rows.Band.Columns("UniFundID").Hidden = True
        grdMapData.Rows.Band.Columns("LinkCount").Hidden = True
        grdMapData.Rows.Band.Columns("MInvestorTypeID").Hidden = True
        grdMapData.Rows.Band.Columns("InvStatusCode").Hidden = True
        grdMapData.Rows.Band.Columns("FundStatusCode").Hidden = True
        grdMapData.Rows.Band.Columns("UniFullName").Hidden = True
        grdMapData.Rows.Band.Columns("RowNumber").Hidden = True
        grdMapData.Rows.Band.Columns("OriginalInvestorID").Hidden = True
        grdMapData.Rows.Band.Columns("OriginalFundID").Hidden = True
        grdMapData.Rows.Band.Columns("InvestorID").Hidden = True
        grdMapData.Rows.Band.Columns("FundID").Hidden = True
        grdMapData.Rows.Band.Columns("EntityID").Hidden = True
        grdMapData.Rows.Band.Columns("ETemplateID").Hidden = True
        grdMapData.Rows.Band.Columns("ClientID").Hidden = True
        grdMapData.Rows.Band.Columns("UserID").Hidden = True
        grdMapData.Rows.Band.Columns("FilingDateCopy").Hidden = True
        grdMapData.Rows.Band.Columns("Doubts").Width = 10
        grdMapData.Rows.Band.Columns("Full Name").Width = 70
        grdMapData.Rows.Band.Columns(mstrMappedInvName).Width = 115
        grdMapData.Rows.Band.Columns(mstrMappedFundName).Width = 117
        If menmSourceTypeCode = SourceTypeCode.PBC Then
            grdMapData.Rows.Band.Columns(mstrMatchCol3).CellAppearance.BorderColor = grdMapData.DisplayLayout.Appearances("RedBorder").BorderColor 'Color.Red
            grdMapData.Rows.Band.Columns(mstrMatchCol4).CellAppearance.BorderColor = grdMapData.DisplayLayout.Appearances("RedBorder").BorderColor
        Else
            If mstrMappedInvName.Equals("") = False Then
                grdMapData.Rows.Band.Columns(mstrMappedInvName).CellAppearance.BorderColor = grdMapData.DisplayLayout.Appearances("RedBorder").BorderColor
            End If
            If mstrMappedFundName.Equals("") = False Then
                grdMapData.Rows.Band.Columns(mstrMappedFundName).CellAppearance.BorderColor = grdMapData.DisplayLayout.Appearances("RedBorder").BorderColor
            End If
        End If
        grdMapData.DisplayLayout.GroupByBox.Hidden = False
        grdMapData.DisplayLayout.Override.ColumnAutoSizeMode = ColumnAutoSizeMode.AllRowsInBand
        grdMapData.DisplayLayout.Override.AllowColSizing = AllowColSizing.Free
        grdMapData.Rows.Band.Columns(mstrPosition).PerformAutoResize(PerformAutoSizeType.VisibleRows)
        If menmSourceTypeCode = SourceTypeCode.PBC Then
            grdMapData.Rows.Band.Columns(mstrMatchCol3).PerformAutoResize(PerformAutoSizeType.VisibleRows)
            grdMapData.Rows.Band.Columns(mstrMatchCol4).PerformAutoResize(PerformAutoSizeType.VisibleRows)
        Else
            For Each lstrMatch As String In marrMatchCols
                grdMapData.Rows.Band.Columns(lstrMatch).PerformAutoResize(PerformAutoSizeType.VisibleRows)
            Next
        End If
        grdMapData.DisplayLayout.Override.AllowUpdate = Infragistics.Win.DefaultableBoolean.True
    End Sub

    ''' <summary>
    ''' To set the controls as per the Investor/Fund in Map Data grid for ePublic.
    ''' </summary>
    ''' <param name="pblnIsFund"></param>
    ''' <remarks></remarks>
    Private Sub SetControlsForInvestorRow(ByVal pblnIsFund As Boolean)
        If pblnIsFund = False Then
            grdFund.DataSource = Nothing
        End If
        chkCreateNewFund.Enabled = pblnIsFund
        cmbFundField.Enabled = pblnIsFund
        txtFundSearchChar.Enabled = pblnIsFund
        txtFund.Enabled = pblnIsFund
        txtFundAddress.Enabled = pblnIsFund
    End Sub

    ''' <summary>
    ''' To set the controls as per the currently active row in Map Data grid.
    ''' </summary>
    ''' <param name="pblnStatus"></param>
    ''' <remarks></remarks>
    Private Sub SetControlsForGroupByRow(ByVal pblnStatus As Boolean)
        If pblnStatus = False Then
            grdInvestor.DataSource = Nothing
            grdFund.DataSource = Nothing
        End If
        chkMarkCustodian.Enabled = pblnStatus
        chkCreateNewInv.Enabled = pblnStatus
        chkCreateNewFund.Enabled = pblnStatus
        gpbSuggestionCriteria.Enabled = pblnStatus
        gpbAdvancedSearch.Enabled = pblnStatus
    End Sub

    ''' <summary>
    ''' To add filter conditions
    ''' </summary>
    ''' <param name="IsDoubleCondition"></param>
    ''' <param name="LogicalOperator"></param>
    ''' <remarks></remarks>
    Private Sub AddFilterConditions(ByVal IsDoubleCondition As Boolean, ByVal LogicalOperator As FilterLogicalOperator)
        Dim rootBand As UltraGridBand
        Try
            rootBand = grdMapData.DisplayLayout.Bands(0)
            rootBand.ColumnFilters.ClearAllFilters()
            'If a blank search is conducted
            If enmSearchTypes = SearchTypes.Blank Then
                rootBand.ColumnFilters.LogicalOperator = FilterLogicalOperator.Or
                'rootBand.ColumnFilters.LogicalOperator = LogicalOperator
                For Each lCol As DataColumn In mdtExcelData.Columns
                    If marrExcludedFromFilters.Contains(lCol.ColumnName) Then Continue For
                    rootBand.ColumnFilters(lCol.ColumnName).FilterConditions.Add(FilterComparisionOperator.Equals, FilterCondition.BlankCellValue)
                    'rootBand.ColumnFilters(lCol.ColumnName).FilterConditions.Add(FilterComparisionOperator.Equals, DBNull.Value)
                Next
                'If a single text search is conducted
            ElseIf enmSearchTypes = SearchTypes.SingleText Then
                rootBand.ColumnFilters.LogicalOperator = FilterLogicalOperator.Or
                'rootBand.ColumnFilters.LogicalOperator = LogicalOperator
                For Each lCol As DataColumn In mdtExcelData.Columns
                    If marrExcludedFromFilters.Contains(lCol.ColumnName) Then Continue For
                    rootBand.ColumnFilters(lCol.ColumnName).FilterConditions.Add(FilterComparisionOperator.Match, "")
                Next
                'If a double text search is conducted
            ElseIf enmSearchTypes = SearchTypes.DoubleText Then
                rootBand.ColumnFilters.LogicalOperator = FilterLogicalOperator.Or
                'rootBand.ColumnFilters.LogicalOperator = LogicalOperator
                For Each lCol As DataColumn In mdtExcelData.Columns
                    If marrExcludedFromFilters.Contains(lCol.ColumnName) Then Continue For
                    rootBand.ColumnFilters(lCol.ColumnName).FilterConditions.Add(FilterComparisionOperator.Match, "")
                    rootBand.ColumnFilters(lCol.ColumnName).FilterConditions.Add(FilterComparisionOperator.Match, "")
                Next
                'If a Doubt search is conducted
            ElseIf enmSearchTypes = SearchTypes.Doubt Then
                rootBand.ColumnFilters.LogicalOperator = FilterLogicalOperator.Or
                rootBand.ColumnFilters("Doubts").FilterConditions.Add(FilterComparisionOperator.Equals, True)
                'If both Investor and Fund are unmapped
            ElseIf enmSearchTypes = SearchTypes.BothUnmapped Then
                rootBand.ColumnFilters.LogicalOperator = FilterLogicalOperator.And
                rootBand.ColumnFilters("InvestorID").FilterConditions.Add(FilterComparisionOperator.Equals, FilterCondition.BlankCellValue)
                rootBand.ColumnFilters("FundID").FilterConditions.Add(FilterComparisionOperator.Equals, FilterCondition.BlankCellValue)
                'If both Investor is unmapped and Fund is mapped
            ElseIf enmSearchTypes = SearchTypes.FundMapped Then
                rootBand.ColumnFilters.LogicalOperator = FilterLogicalOperator.And
                rootBand.ColumnFilters("InvestorID").FilterConditions.Add(FilterComparisionOperator.Equals, FilterCondition.BlankCellValue)
                rootBand.ColumnFilters("FundID").FilterConditions.Add(FilterComparisionOperator.Equals, FilterCondition.NonBlankCellValue)
                'If Investor is mapped and Fund is unmapped
            ElseIf enmSearchTypes = SearchTypes.InvestorMapped Then
                rootBand.ColumnFilters.LogicalOperator = FilterLogicalOperator.And
                rootBand.ColumnFilters("InvestorID").FilterConditions.Add(FilterComparisionOperator.Equals, FilterCondition.NonBlankCellValue)
                rootBand.ColumnFilters("FundID").FilterConditions.Add(FilterComparisionOperator.Equals, FilterCondition.BlankCellValue)
                'If both Investor and Fund are mapped
            ElseIf enmSearchTypes = SearchTypes.BothMapped Then
                rootBand.ColumnFilters.LogicalOperator = FilterLogicalOperator.And
                rootBand.ColumnFilters("InvestorID").FilterConditions.Add(FilterComparisionOperator.Equals, FilterCondition.NonBlankCellValue)
                rootBand.ColumnFilters("FundID").FilterConditions.Add(FilterComparisionOperator.Equals, FilterCondition.NonBlankCellValue)
                'If Change Log search is conducted
            ElseIf enmSearchTypes = SearchTypes.ChangeLog Then
                rootBand.ColumnFilters.LogicalOperator = FilterLogicalOperator.And
                rootBand.ColumnFilters("RowNumber").FilterConditions.Add(FilterComparisionOperator.Equals, mstrSearchText)
                rootBand.ColumnFilters("HasChangeLog").FilterConditions.Add(FilterComparisionOperator.Equals, True)
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            rootBand = Nothing
        End Try
    End Sub

    Private Sub LoadDropDowns()
        LoadFields()
    End Sub

    ''' <summary>
    ''' To set the default field values in the drop downs
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SetDefaultFieldValues()
        Dim lstrQuery As String
        Dim larrMappedCol() As DataRow
        Try
            'For Public
            If menmSourceTypeCode = SourceTypeCode.PBC Then
                'Setting default value for Investor Suggestion Field. If Mapped Investor Name column exists, then this should be default selected field
                lstrQuery = "DBFieldName ='" + PublicMapColumns.MappedInvestorName.ToString + "'"
                larrMappedCol = mdtColMapping.Select(lstrQuery)
                If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                    mstrSelectedInvestorField = larrMappedCol(0).Item("Map Field")
                    mstrExcelInvestorField = mstrSelectedInvestorField
                Else
                    'Otherwise, select InvEntityID
                    lstrQuery = "DBFieldName ='" + PublicMapColumns.InvEntityID.ToString + "'"
                    larrMappedCol = mdtColMapping.Select(lstrQuery)
                    If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                        mstrSelectedInvestorField = larrMappedCol(0).Item("Map Field")
                        mstrExcelInvestorField = mstrSelectedInvestorField
                    End If
                End If

                'Setting default value for Fund Suggestion Field. If Mapped Investor Name column exists, then this should be default selected field
                lstrQuery = "DBFieldName ='" + PublicMapColumns.MappedFundName.ToString + "'"
                larrMappedCol = mdtColMapping.Select(lstrQuery)
                If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                    mstrSelectedFundField = larrMappedCol(0).Item("Map Field")
                    mstrExcelFundField = mstrSelectedFundField
                Else
                    'Otherwise, select FundEntityID
                    lstrQuery = "DBFieldName ='" + PublicMapColumns.FundEntityID.ToString + "'"
                    larrMappedCol = mdtColMapping.Select(lstrQuery)
                    If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                        mstrSelectedFundField = larrMappedCol(0).Item("Map Field")
                        mstrExcelFundField = mstrSelectedFundField
                    End If
                End If
                'For Registers, Banklist, DDI
            Else
                'Setting default value for Investor Suggestion Field, First Priority is to MappedInvestorName
                lstrQuery = "DBFieldName ='" + RegMapColumns.MappedInvestorName.ToString + "'"
                larrMappedCol = mdtColMapping.Select(lstrQuery)
                If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                    mstrSelectedInvestorField = larrMappedCol(0).Item("Map Field")
                    mstrExcelInvestorField = mstrSelectedInvestorField
                Else
                    'Second Priority is to MatchCol1
                    lstrQuery = "DBFieldName ='" + RegMapColumns.MatchCol1.ToString + "'"
                    larrMappedCol = mdtColMapping.Select(lstrQuery)
                    If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                        mstrSelectedInvestorField = larrMappedCol(0).Item("Map Field")
                    End If
                End If

                'Setting default value for Fund Suggestion Field, First Priority is to MappedFundName
                lstrQuery = "DBFieldName ='" + RegMapColumns.MappedFundName.ToString + "'"
                larrMappedCol = mdtColMapping.Select(lstrQuery)
                If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                    mstrSelectedFundField = larrMappedCol(0).Item("Map Field")
                    mstrExcelFundField = mstrSelectedFundField
                Else
                    'Second Priority is to MatchCol2
                    lstrQuery = "DBFieldName ='" + RegMapColumns.MatchCol2.ToString + "'"
                    larrMappedCol = mdtColMapping.Select(lstrQuery)
                    If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                        mstrSelectedFundField = larrMappedCol(0).Item("Map Field")
                    Else
                        'Third Priority is to MatchCol1
                        lstrQuery = "DBFieldName ='" + RegMapColumns.MatchCol1.ToString + "'"
                        larrMappedCol = mdtColMapping.Select(lstrQuery)
                        If larrMappedCol.Length = 1 AndAlso larrMappedCol(0).Item("Map Field").ToString <> "" Then
                            mstrSelectedFundField = larrMappedCol(0).Item("Map Field")
                        End If
                    End If
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            larrMappedCol = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' To save the excel column names in variables and array
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SetColumnNames()
        Dim lstrQuery As String
        Dim larrMappedCol() As DataRow
        Try
            'Setting name value for Match Columns
            If menmSourceTypeCode = SourceTypeCode.PBC Then
                lstrQuery = "DBFieldName ='" + PublicMapColumns.InvEntityID.ToString + "'"
                larrMappedCol = mdtColMapping.Select(lstrQuery)
                If larrMappedCol.Length = 1 Then
                    If larrMappedCol(0).Item("Map Field").ToString = "" Then
                        mstrMatchCol1 = ""
                    Else
                        mstrMatchCol1 = larrMappedCol(0).Item("Map Field")
                        mintMatchColCount += 1
                        marrMatchCols(marrMatchCols.Length - 1) = mstrMatchCol1
                    End If
                End If

                lstrQuery = "DBFieldName ='" + PublicMapColumns.FundEntityID.ToString + "'"
                larrMappedCol = mdtColMapping.Select(lstrQuery)
                If larrMappedCol.Length = 1 Then
                    If larrMappedCol(0).Item("Map Field").ToString = "" Then
                        mstrMatchCol2 = ""
                    Else
                        If marrMatchCols(0) IsNot Nothing Then
                            ReDim Preserve marrMatchCols(marrMatchCols.Length)
                        End If
                        mstrMatchCol2 = larrMappedCol(0).Item("Map Field")
                        mintMatchColCount += 1
                        marrMatchCols(marrMatchCols.Length - 1) = mstrMatchCol2
                    End If
                End If

                lstrQuery = "DBFieldName ='" + PublicMapColumns.MappedInvestorName.ToString + "'"
                larrMappedCol = mdtColMapping.Select(lstrQuery)
                If larrMappedCol.Length = 1 Then
                    If larrMappedCol(0).Item("Map Field").ToString = "" Then
                        mstrMatchCol3 = ""
                    Else
                        If marrMatchCols(0) IsNot Nothing Then
                            ReDim Preserve marrMatchCols(marrMatchCols.Length)
                        End If
                        mstrMatchCol3 = larrMappedCol(0).Item("Map Field")
                        mintMatchColCount += 1
                        marrMatchCols(marrMatchCols.Length - 1) = mstrMatchCol3
                    End If
                End If

                lstrQuery = "DBFieldName ='" + PublicMapColumns.MappedFundName.ToString + "'"
                larrMappedCol = mdtColMapping.Select(lstrQuery)
                If larrMappedCol.Length = 1 Then
                    If larrMappedCol(0).Item("Map Field").ToString = "" Then
                        mstrMatchCol4 = ""
                    Else
                        ReDim Preserve marrMatchCols(marrMatchCols.Length)
                        mstrMatchCol4 = larrMappedCol(0).Item("Map Field")
                        mintMatchColCount += 1
                        marrMatchCols(marrMatchCols.Length - 1) = mstrMatchCol4
                    End If
                End If

                mstrMatchCol5 = ""

                lstrQuery = "DBFieldName ='" + RegMapColumns.Position.ToString + "'"
                larrMappedCol = mdtColMapping.Select(lstrQuery)
                If larrMappedCol.Length = 1 Then
                    If larrMappedCol(0).Item("Map Field").ToString = "" Then
                        mstrPosition = ""
                    Else
                        mstrPosition = larrMappedCol(0).Item("Map Field")
                    End If
                End If
            Else
                lstrQuery = "DBFieldName ='" + RegMapColumns.MatchCol1.ToString + "'"
                larrMappedCol = mdtColMapping.Select(lstrQuery)
                If larrMappedCol.Length = 1 Then
                    If larrMappedCol(0).Item("Map Field").ToString = "" Then
                        mstrMatchCol1 = ""
                    Else
                        mstrMatchCol1 = larrMappedCol(0).Item("Map Field")
                        mintMatchColCount += 1
                        marrMatchCols(marrMatchCols.Length - 1) = mstrMatchCol1
                    End If
                End If

                lstrQuery = "DBFieldName ='" + RegMapColumns.MatchCol2.ToString + "'"
                larrMappedCol = mdtColMapping.Select(lstrQuery)
                If larrMappedCol.Length = 1 Then
                    If larrMappedCol(0).Item("Map Field").ToString = "" Then
                        mstrMatchCol2 = ""
                    Else
                        ReDim Preserve marrMatchCols(marrMatchCols.Length)
                        mstrMatchCol2 = larrMappedCol(0).Item("Map Field")
                        mintMatchColCount += 1
                        marrMatchCols(marrMatchCols.Length - 1) = mstrMatchCol2
                    End If
                End If

                lstrQuery = "DBFieldName ='" + RegMapColumns.MatchCol3.ToString + "'"
                larrMappedCol = mdtColMapping.Select(lstrQuery)
                If larrMappedCol.Length = 1 Then
                    If larrMappedCol(0).Item("Map Field").ToString = "" Then
                        mstrMatchCol3 = ""
                    Else
                        ReDim Preserve marrMatchCols(marrMatchCols.Length)
                        mstrMatchCol3 = larrMappedCol(0).Item("Map Field")
                        mintMatchColCount += 1
                        marrMatchCols(marrMatchCols.Length - 1) = mstrMatchCol3
                    End If
                End If

                lstrQuery = "DBFieldName ='" + RegMapColumns.MatchCol4.ToString + "'"
                larrMappedCol = mdtColMapping.Select(lstrQuery)
                If larrMappedCol.Length = 1 Then
                    If larrMappedCol(0).Item("Map Field").ToString = "" Then
                        mstrMatchCol4 = ""
                    Else
                        ReDim Preserve marrMatchCols(marrMatchCols.Length)
                        mstrMatchCol4 = larrMappedCol(0).Item("Map Field")
                        mintMatchColCount += 1
                        marrMatchCols(marrMatchCols.Length - 1) = mstrMatchCol4
                    End If
                End If

                lstrQuery = "DBFieldName ='" + RegMapColumns.MatchCol5.ToString + "'"
                larrMappedCol = mdtColMapping.Select(lstrQuery)
                If larrMappedCol.Length = 1 Then
                    If larrMappedCol(0).Item("Map Field").ToString = "" Then
                        mstrMatchCol5 = ""
                    Else
                        ReDim Preserve marrMatchCols(marrMatchCols.Length)
                        mstrMatchCol5 = larrMappedCol(0).Item("Map Field")
                        mintMatchColCount += 1
                        marrMatchCols(marrMatchCols.Length - 1) = mstrMatchCol5
                    End If
                End If

                lstrQuery = "DBFieldName ='" + RegMapColumns.Position.ToString + "'"
                larrMappedCol = mdtColMapping.Select(lstrQuery)
                If larrMappedCol.Length = 1 Then
                    If larrMappedCol(0).Item("Map Field").ToString = "" Then
                        mstrPosition = ""
                    Else
                        mstrPosition = larrMappedCol(0).Item("Map Field")
                    End If
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            larrMappedCol = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' To load Investor and Fund field drop downs
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub LoadFields()
        Dim ldtInvestorFields As DataTable = Nothing
        Dim ldtFundFields As DataTable = Nothing
        Dim ldrInvestorField As DataRow = Nothing
        Dim lintFieldValue As Int16 = 1
        Dim lstrQuery As String
        Dim larrSelectedField() As DataRow
        Try
            ldtInvestorFields = New DataTable
            ldtFundFields = New DataTable
            ldtInvestorFields.Columns.Add("FieldID", GetType(Int16))
            ldtInvestorFields.Columns.Add("FieldName", GetType(String))

            For Each lCol As UltraGridColumn In grdMapData.Rows.Band.Columns
                If lCol.Hidden = False Then
                    ldrInvestorField = ldtInvestorFields.NewRow
                    ldrInvestorField.Item("FieldID") = lintFieldValue
                    ldrInvestorField.Item("FieldName") = lCol.Header.Caption
                    ldtInvestorFields.Rows.Add(ldrInvestorField)
                    lintFieldValue += 1
                End If
            Next

            cmbInvestorField.DataSource = ldtInvestorFields

            ldtFundFields = ldtInvestorFields.Copy
            cmbFundField.DataSource = ldtFundFields

            'If mstrSelectedInvestorField
            'Dim lblnIsCorrect As Boolean = True

            If mstrSelectedInvestorField.Equals("") = False Then
                lstrQuery = "FieldName ='" + mstrSelectedInvestorField + "'"
                larrSelectedField = ldtInvestorFields.Select(lstrQuery)
                If larrSelectedField.Length = 1 Then
                    cmbInvestorField.SelectedIndex = ldtInvestorFields.Rows.IndexOf(larrSelectedField(0))
                End If
            End If

            If mstrSelectedFundField.Equals("") = False Then
                lstrQuery = "FieldName ='" + mstrSelectedFundField + "'"
                larrSelectedField = ldtFundFields.Select(lstrQuery)
                If larrSelectedField.Length = 1 Then
                    cmbFundField.SelectedIndex = ldtFundFields.Rows.IndexOf(larrSelectedField(0))
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            ldtInvestorFields = Nothing
            ldtFundFields = Nothing
            ldrInvestorField = Nothing
            larrSelectedField = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' To filter the rows from Map Data on the basis of Advanced Search
    ''' </summary>
    ''' <param name="strText"></param>
    ''' <remarks></remarks>
    Private Sub FilterRows(ByVal strText As String)
        Dim lstrSearch() As String
        Try
            Dim lblnIsTwoText As Boolean = False
            'Check if it contains an AND or OR search,  If yes, set the operator and the boolean variable
            If strText.Contains(mstrANDOperator) Then
                mSelectedOperator = FilterLogicalOperator.And
                lblnIsTwoText = True
            ElseIf strText.Contains(mstrOROperator) Then
                mSelectedOperator = FilterLogicalOperator.Or
                lblnIsTwoText = True
            End If

            'Set the SearchType, check if its Blank, Single or Double 
            If strText.Trim = "" Then
                enmSearchTypes = SearchTypes.Blank
            ElseIf lblnIsTwoText Then
                enmSearchTypes = SearchTypes.DoubleText
            Else
                enmSearchTypes = SearchTypes.SingleText
            End If

            If enmSearchTypes = SearchTypes.Blank Then
                AddFilterConditions(True, FilterLogicalOperator.Or)
                For Each lCol As DataColumn In mdtExcelData.Columns
                    If grdMapData.Rows.ColumnFilters(lCol.ColumnName).FilterConditions.Count > 0 Then
                        'grdMapData.Rows.ColumnFilters(lCol.ColumnName).FilterConditions(0).CompareValue = ""
                        grdMapData.Rows.ColumnFilters(lCol.ColumnName).FilterConditions(0).CompareValue = DBNull.Value
                        grdMapData.Rows.ColumnFilters(lCol.ColumnName).FilterConditions(0).ComparisionOperator = FilterComparisionOperator.Match
                    End If
                Next
            ElseIf enmSearchTypes = SearchTypes.SingleText Then
                AddFilterConditions(True, FilterLogicalOperator.Or)
                For Each lCol As DataColumn In mdtExcelData.Columns
                    If grdMapData.Rows.ColumnFilters(lCol.ColumnName).FilterConditions.Count > 0 Then
                        If menmAdvancedComparisonOperator = FilterComparisionOperator.StartsWith Then
                            grdMapData.Rows.ColumnFilters(lCol.ColumnName).FilterConditions(0).CompareValue = "^" + strText
                        Else
                            grdMapData.Rows.ColumnFilters(lCol.ColumnName).FilterConditions(0).CompareValue = strText
                        End If
                        grdMapData.Rows.ColumnFilters(lCol.ColumnName).FilterConditions(0).ComparisionOperator = FilterComparisionOperator.Match
                    End If
                Next
            ElseIf enmSearchTypes = SearchTypes.DoubleText Then
                If mSelectedOperator = FilterLogicalOperator.And Then
                    lstrSearch = strText.Split(mstrANDOperator)
                Else
                    lstrSearch = strText.Split(mstrOROperator)
                End If
                'If Begins With
                If menmAdvancedComparisonOperator = FilterComparisionOperator.StartsWith Then
                    lstrSearch(0) = "^" + lstrSearch(0)
                    lstrSearch(1) = "^" + lstrSearch(1)
                End If
                AddFilterConditions(True, mSelectedOperator)
                For Each lCol As DataColumn In mdtExcelData.Columns
                    If grdMapData.Rows.ColumnFilters(lCol.ColumnName).FilterConditions.Count > 0 Then
                        grdMapData.Rows.ColumnFilters(lCol.ColumnName).LogicalOperator = mSelectedOperator
                        grdMapData.Rows.ColumnFilters(lCol.ColumnName).FilterConditions(0).CompareValue = lstrSearch(0)
                        grdMapData.Rows.ColumnFilters(lCol.ColumnName).FilterConditions(0).ComparisionOperator = FilterComparisionOperator.Match
                        grdMapData.Rows.ColumnFilters(lCol.ColumnName).FilterConditions(1).CompareValue = lstrSearch(1)
                        grdMapData.Rows.ColumnFilters(lCol.ColumnName).FilterConditions(1).ComparisionOperator = FilterComparisionOperator.Match
                    End If
                Next
            End If
            grdMapData.DisplayLayout.RefreshFilters()
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        End Try
    End Sub

    ''' <summary>
    ''' To Find and Underline the searched pharse
    ''' </summary>
    ''' <param name="grdData"></param>
    ''' <param name="strText"></param>
    ''' <param name="pblnIsAll"></param>
    ''' <remarks></remarks>
    Public Sub FindAndUnderlinePhrase(ByVal grdData As Crystal.CustomControls.CrystalUltraGrid, ByVal strText As String, ByVal pblnIsAll As Boolean)
        Dim lblnSuccess As Boolean = False
        Dim lstrSearch() As String = Nothing
        Try
            'Check if the Search Type is Double Text
            If enmSearchTypes = SearchTypes.DoubleText Then
                If mSelectedOperator = FilterLogicalOperator.And Then
                    lstrSearch = strText.Split(mstrANDOperator)
                Else
                    lstrSearch = strText.Split(mstrOROperator)
                End If
                'If Beigns With
                If menmAdvancedComparisonOperator = FilterComparisionOperator.StartsWith Then
                    lstrSearch(0) = "^" + lstrSearch(0)
                    lstrSearch(1) = "^" + lstrSearch(1)
                End If
            ElseIf enmSearchTypes = SearchTypes.SingleText AndAlso menmAdvancedComparisonOperator = FilterComparisionOperator.StartsWith Then
                strText = "^" + strText
            End If

            For Each r As UltraGridRow In grdData.Rows
                'If the row is FilteredOut then ignore
                If r.IsFilteredOut Then Continue For
                For Each c As UltraGridCell In r.Cells
                    'If the column is excluded from filter then ignore
                    If marrExcludedFromFilters.Contains(c.Column.Header.Caption) Then Continue For
                    'If All radio button is selected, then set the appearance to normal.
                    If pblnIsAll Then
                        c.Appearance.BorderColor = Color.Silver
                        c.Appearance.FontData.Underline = Infragistics.Win.DefaultableBoolean.False
                    Else
                        'Check if the current's cell's text matches the criteria
                        If enmSearchTypes = SearchTypes.Blank Then
                            If c.Text = strText Then
                                lblnSuccess = True
                            Else
                                lblnSuccess = False
                            End If
                        Else
                            If enmSearchTypes = SearchTypes.DoubleText Then
                                If mSelectedOperator = FilterLogicalOperator.And Then
                                    If Regex.Match(c.Text, lstrSearch(0), RegexOptions.IgnoreCase).Success AndAlso Regex.Match(c.Text, lstrSearch(1), RegexOptions.IgnoreCase).Success Then
                                        lblnSuccess = True
                                    Else
                                        lblnSuccess = False
                                    End If
                                Else
                                    If Regex.Match(c.Text, lstrSearch(0), RegexOptions.IgnoreCase).Success OrElse Regex.Match(c.Text, lstrSearch(1), RegexOptions.IgnoreCase).Success Then
                                        lblnSuccess = True
                                    Else
                                        lblnSuccess = False
                                    End If
                                End If
                            Else
                                If Regex.Match(c.Text, strText, RegexOptions.IgnoreCase).Success Then
                                    lblnSuccess = True
                                Else
                                    lblnSuccess = False
                                End If
                            End If
                            'If success then highlighlt
                            If lblnSuccess Then
                                c.Appearance.BorderColor = Color.Black
                                c.Appearance.FontData.Underline = Infragistics.Win.DefaultableBoolean.True
                            ElseIf c.Appearance.FontData.Underline = Infragistics.Win.DefaultableBoolean.True Then
                                c.Appearance.BorderColor = Color.Silver
                                c.Appearance.FontData.Underline = Infragistics.Win.DefaultableBoolean.False
                            End If
                        End If
                    End If
                Next
            Next

            If grdMapData.Rows.FilteredInRowCount > 0 Then
                'Activate/Highlight the first filtered/searched cell in row in the grid
                For Each lMapRow As UltraGridRow In grdMapData.Rows
                    If lMapRow.IsFilteredOut = False Then
                        If grdMapData.Selected.Cells.Count > 0 Then
                            For Each lCell As UltraGridCell In grdMapData.Selected.Cells
                                lCell.Selected = False
                            Next
                        End If
                        lMapRow.Activated = True
                        Exit For
                    End If
                Next
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            lstrSearch = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' To save the Investor/Fund Mapping in the MapData grid
    ''' </summary>
    ''' <param name="grdData"></param>
    ''' <param name="pblnIsInvestor"></param>
    ''' <param name="pintFundID"></param>
    ''' <remarks></remarks>
    Private Sub SaveInvestorFundMapping(ByVal grdData As UltraGrid, ByVal pblnIsInvestor As Boolean, ByVal pintFundID As Integer)
        Dim status As Boolean = False
        If (grdData.ActiveCell Is Nothing) Then Exit Sub
        If (grdData.ActiveRow Is Nothing) Then Exit Sub
        Dim lActiveRow As UltraGridRow = grdMapData.ActiveRow
        Dim larrMappedInv() As DataRow = Nothing
        Dim larrMappedRow() As DataRow = Nothing
        Dim ldtFundData As DataTable = Nothing
        Dim lblnCanUseCurrentInv As Boolean
        Dim lstrQuery As String
        Dim lintNewTickableRowIndexinFund As Integer
        Try
            'Tick/Un-Tick funcationality, Go ahead only if the ticked cell is "M"
            If (grdData.ActiveCell.Column.Header.Caption = "M") Then
                status = grdData.ActiveCell.Value
                'If the current status is true, then set it to False
                If (status = True) Then
                    grdData.ActiveRow.Cells("M").Value = False
                    If pblnIsInvestor Then
                        SetInvestorRelatedFields(grdMapData.ActiveRow, Nothing, Nothing, InvestorMappingChangesSource.SuggestoinsFromInv)

                    Else
                        SetFundRelatedFields(grdMapData.ActiveRow, Nothing, Nothing, FundMappingChangesSource.Suggestoins)
                    End If
                Else
                    UntickAllTickedRows(grdData)
                    'Dim larrMappedCol() As DataRow
                    ''Un-Tick other rows in the grid
                    'larrMappedCol = CType(grdData.DataSource, DataTable).Select("M=True")
                    'If larrMappedCol.Length > 0 Then
                    '    For Each lRow As DataRow In larrMappedCol
                    '        lRow.Item("M") = False
                    '    Next
                    'End If

                    'Tick the selected/active row
                    grdData.ActiveRow.Cells("M").Value = True
                    If pblnIsInvestor Then
                        SetInvestorRelatedFields(grdMapData.ActiveRow, Nothing, grdInvestor.ActiveRow, InvestorMappingChangesSource.SuggestoinsFromInv)
                    Else
                        SetFundRelatedFields(grdMapData.ActiveRow, Nothing, grdFund.ActiveRow, FundMappingChangesSource.Suggestoins)
                        'If the selected Fund is linked to some investor then the linked investor should be mapped based on following conditions.
                        If grdFund.ActiveRow.GetCellValue("InvestorID") IsNot DBNull.Value Then
                            lblnCanUseCurrentInv = False
                            If grdMapData.ActiveRow.GetCellValue("InvestorID") Is DBNull.Value Then
                                lblnCanUseCurrentInv = True
                            ElseIf grdMapData.ActiveRow.GetCellValue("InvestorID") = grdFund.ActiveRow.GetCellValue("InvestorID") Then
                                lblnCanUseCurrentInv = True
                            Else
                                If MessageBox.Show("Replace existing investor mapping with linked investor?", CommonCLL.mstrMsgBoxCaption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) = DialogResult.Yes Then
                                    lblnCanUseCurrentInv = True
                                End If
                            End If
                            'If the newly selected Investor/Fund can be used, then update the investor fields in Map/Excel grid
                            If lblnCanUseCurrentInv Then
                                SetInvestorRelatedFields(grdMapData.ActiveRow, Nothing, grdFund.ActiveRow, InvestorMappingChangesSource.SuggestoinsFromFund)
                                'grdMapData.ActiveRow.Cells("InvestorID").Value = grdFund.ActiveRow.Cells("InvestorID").Value
                                'grdMapData.ActiveRow.Cells(mstrMappedInvName).Value = grdFund.ActiveRow.Cells("Linked Inv.").Value
                                'grdMapData.ActiveRow.Cells("MInvestorTypeID").Value = grdFund.ActiveRow.Cells("MInvestorTypeID").Value
                                'grdMapData.ActiveRow.Cells("InvStatusCode").Value = grdFund.ActiveRow.Cells("InvStatusCode").Value
                                'grdMapData.ActiveRow.Cells("InvEntityID").Value = grdFund.ActiveRow.Cells("InvEntityID").Value
                                'If grdMapData.ActiveRow.Cells("UniInvestorID").Value Is DBNull.Value Then
                                '    grdMapData.ActiveRow.Cells("UniInvestorID").Value = grdFund.ActiveRow.Cells("InvestorID").Value
                                'End If
                            Else
                                ldtFundData = grdFund.DataSource
                                'Check if the already mapped Investor exists in the Fund grid, If yes, then tick it.
                                lstrQuery = "InvestorID ='" + grdMapData.ActiveRow.GetCellValue("InvestorID").ToString + "' AND FundID='" + grdMapData.ActiveRow.GetCellValue("FundID").ToString + "'"
                                larrMappedInv = ldtFundData.Select(lstrQuery)
                                'If the already mapped Investor does not exist, then find the alone fund and tick it.
                                If larrMappedInv.Length = 0 Then
                                    lstrQuery = "InvestorID IS NULL AND FundID='" + grdMapData.ActiveRow.GetCellValue("FundID").ToString + "'"
                                    larrMappedInv = ldtFundData.Select(lstrQuery)
                                End If
                                If larrMappedInv.Length = 1 Then
                                    grdData.ActiveRow.Cells("M").Value = False
                                    lintNewTickableRowIndexinFund = ldtFundData.Rows.IndexOf(larrMappedInv(0))
                                    grdData.ActiveRow.Cells("M").Selected = False
                                    grdData.Rows(lintNewTickableRowIndexinFund).Activated = True
                                    grdData.Rows(lintNewTickableRowIndexinFund).Cells("M").Activated = True
                                    grdData.Rows(lintNewTickableRowIndexinFund).Cells("M").Value = True
                                End If
                            End If
                        End If
                    End If
                End If
                grdData.ActiveCell = Nothing
                'grdMapData.ActiveRow.Cells("Full Name").Value = CommonCLL.UserFullName
                'grdMapData.ActiveRow.Cells("UserID").Value = CommonCLL.UserID

                'If the record is unticked, and Universal mapping differs from the actual mapping then autoselect the universal mapping.
                If pblnIsInvestor Then
                    AutoSelectUniveralMapping(grdInvestor, pblnIsInvestor, grdMapData.ActiveRow.GetCellValue("UniInvestorID").Equals(grdInvestor.ActiveRow.GetCellValue("InvestorID")))
                Else
                    AutoSelectUniveralMapping(grdFund, pblnIsInvestor, grdMapData.ActiveRow.GetCellValue("UniFundID").Equals(grdFund.ActiveRow.GetCellValue("FundID")))
                End If
                CType(grdData.DataSource, DataTable).AcceptChanges()
                CType(grdMapData.DataSource, DataTable).AcceptChanges()
                mblnAnyDataChange = True
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            larrMappedInv = Nothing
            ldtFundData = Nothing
            larrMappedRow = Nothing
        End Try
    End Sub

    Private Sub UntickAllTickedRows(ByVal grdData As CrystalUltraGrid)
        If grdData.DataSource Is Nothing Then Exit Sub
        Dim larrMappedCol() As DataRow
        'Un-Tick other rows in the grid
        larrMappedCol = CType(grdData.DataSource, DataTable).Select("M=True")
        If larrMappedCol.Length > 0 Then
            For Each lRow As DataRow In larrMappedCol
                lRow.Item("M") = False
            Next
        End If
    End Sub

    ''' <summary>
    ''' To auto-select the universal mapping OR blank when a client mapping/universal mapping is un-ticked
    ''' </summary>
    ''' <param name="grdData"></param>
    ''' <param name="pblnIsInvestor"></param>
    ''' <remarks></remarks>
    Private Sub AutoSelectUniveralMapping(ByVal grdData As UltraGrid, ByVal pblnIsInvestor As Boolean, ByVal pblnIsCurrentRowUniClientMappingSame As Boolean)
        If grdMapData.ActiveRow Is Nothing Then Exit Sub
        Dim lurNewTickingRowInMapData As UltraGridRow
        Dim lActiveRow As UltraGridRow = grdMapData.ActiveRow
        Dim lintTickedInvestorID As Integer
        Dim lintTickedFundID As Integer
        Try
            If grdData.ActiveRow.GetCellValue("M") = False Then
                If pblnIsInvestor Then
                    'If the Universal Mapping differs from actual Mapping andalso if current row's universal and client mappings are not same
                    If grdMapData.ActiveRow.GetCellValue("UniInvestorID").Equals(grdMapData.ActiveRow.GetCellValue("InvestorID")) = False AndAlso _
                        pblnIsCurrentRowUniClientMappingSame = False AndAlso grdMapData.ActiveRow.GetCellValue("UniInvestorID") IsNot DBNull.Value AndAlso _
                        grdMapData.ActiveRow.GetCellValue("InvestorID") Is DBNull.Value Then
                        lintTickedInvestorID = -1
                        If lActiveRow.GetCellValue("UniInvestorID") IsNot DBNull.Value Then
                            'Set the Ticking Investor
                            lintTickedInvestorID = lActiveRow.GetCellValue("UniInvestorID")
                        End If

                        If lintTickedInvestorID <> -1 Then
                            Dim larrMappedRow() As DataRow
                            'Dim lintTickedRowIndexinMapData As Integer
                            'Find the row in the grid and tick it; Save the new mapping in the Map Data grid
                            larrMappedRow = CType(grdData.DataSource, DataTable).Select("InvestorID ='" + lintTickedInvestorID.ToString + "'")
                            If larrMappedRow.Length = 1 Then
                                '''''''''''''''''''''''''''''''''''''''''''''
                                'To avoid Sorting issues
                                'lintTickedRowIndexinMapData = CType(grdInvestor.DataSource, DataTable).Rows.IndexOf(larrMappedRow(0))
                                'grdData.ActiveRow.Cells("M").Selected = False
                                'grdData.Rows(lintTickedRowIndexinMapData).Activated = True
                                'grdData.Rows(lintTickedRowIndexinMapData).Cells("M").Activated = True

                                'grdInvestor.Rows.GetRowWithListIndex(CType(grdInvestor.DataSource, DataTable).Rows.IndexOf(larrMappedRow(0))).Cells("M").Value = True
                                lurNewTickingRowInMapData = grdData.Rows.GetRowWithListIndex(CType(grdData.DataSource, DataTable).Rows.IndexOf(larrMappedRow(0)))
                                If lurNewTickingRowInMapData.GetCellValue("InvStatusCode") <> Crystal.CLL.EntityStatus.EXTNT.ToString AndAlso _
                                    lurNewTickingRowInMapData.GetCellValue("InvStatusCode") <> Crystal.CLL.EntityStatus.DELTE.ToString Then
                                    grdData.ActiveRow.Cells("M").Selected = False
                                    lurNewTickingRowInMapData.Activated = True
                                    lurNewTickingRowInMapData.Cells("M").Activated = True
                                    SaveInvestorFundMapping(grdData, grdData.ActiveRow.GetCellValue("InvestorID"), 0)
                                    grdData.UpdateData()
                                End If
                            End If
                        End If
                    End If
                Else
                    'If the Universal Mapping differs from actual Mapping andalso if current row's universal and client mappings are not same
                    If grdMapData.ActiveRow.GetCellValue("UniFundID").Equals(grdMapData.ActiveRow.GetCellValue("FundID")) = False AndAlso _
                        pblnIsCurrentRowUniClientMappingSame = False AndAlso grdMapData.ActiveRow.GetCellValue("UniFundID") IsNot DBNull.Value AndAlso _
                        grdMapData.ActiveRow.GetCellValue("FundID") Is DBNull.Value Then
                        lintTickedFundID = -1
                        If lActiveRow.GetCellValue("UniFundID") IsNot DBNull.Value Then
                            'Set the Ticking Investor
                            lintTickedFundID = lActiveRow.GetCellValue("UniFundID")
                        End If
                        If lintTickedFundID <> -1 Then
                            Dim larrMappedRow() As DataRow
                            'Dim lintTickedRowIndexinMapData As Integer
                            'Find the row in the grid and tick it; Save the new mapping in the Map Data grid
                            larrMappedRow = CType(grdData.DataSource, DataTable).Select("FundID='" + lintTickedFundID.ToString + "'")
                            If larrMappedRow.Length >= 1 Then
                                'lintTickedRowIndexinMapData = CType(grdFund.DataSource, DataTable).Rows.IndexOf(larrMappedRow(0))
                                lurNewTickingRowInMapData = grdData.Rows.GetRowWithListIndex(CType(grdData.DataSource, DataTable).Rows.IndexOf(larrMappedRow(0)))
                                If lurNewTickingRowInMapData.GetCellValue("FundStatusCode") <> Crystal.CLL.EntityStatus.EXTNT.ToString AndAlso _
                                    lurNewTickingRowInMapData.GetCellValue("FundStatusCode") <> Crystal.CLL.EntityStatus.DELTE.ToString Then
                                    grdData.ActiveRow.Cells("M").Selected = False
                                    lurNewTickingRowInMapData.Activated = True
                                    lurNewTickingRowInMapData.Cells("M").Activated = True
                                    SaveInvestorFundMapping(grdData, 0, grdData.ActiveRow.GetCellValue("FundID"))
                                    grdData.UpdateData()
                                End If
                                'lintTickedRowIndexinMapData = CType(grdFund.DataSource, DataTable).Rows.IndexOf(larrMappedRow(0))
                                'grdData.ActiveRow.Cells("M").Selected = False
                                'grdData.Rows(lintTickedRowIndexinMapData).Activated = True
                                'grdData.Rows(lintTickedRowIndexinMapData).Cells("M").Activated = True
                                'SaveInvestorFundMapping(grdData, 0, grdFund.ActiveRow.Cells("FundID").Value)
                            End If
                        End If
                    End If
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            lActiveRow = Nothing
            lurNewTickingRowInMapData = Nothing
        End Try
    End Sub

    'Function FindRowByCellValue(ByVal Grid, ByVal ChildView, ByVal ColName As String, ByVal SoughtValue As String)
    '    grdFund.Rows.GetAllNonGroupByRows()
    '    Dim Val, i

    '    If ChildView Is Nothing Then
    '        ChildView = Grid
    '    End If

    '    Val = Convert.VarToStr(SoughtValue)

    '    ' Iterate through grid rows
    '    For i = 0 To ChildView.wRowCount - 1
    '        ' Compare the cell value with the specified value
    '        If aqConvert.VarToStr(ChildView.wValue(i, ColName)) = Val Then
    '            FindRowByCellValue = i ' Row is found
    '            Exit Function
    '        End If
    '    Next

    '    FindRowByCellValue = -1 ' Row is not found
    'End Function

    ''' <summary>
    ''' Conduct the Suggestion/Advanced Search
    ''' </summary>
    ''' <param name="pstrInvestorSearch"></param>
    ''' <param name="pstrFundSearch"></param>
    ''' <param name="pstrInvAddress"></param>
    ''' <param name="pstrFundAddress"></param>
    ''' <remarks></remarks>
    Private Sub ConductSearch(ByVal pstrInvestorSearch As String, ByVal pstrFundSearch As String, ByVal pstrInvAddress As String, ByVal pstrFundAddress As String, ByVal pintInvestorSearchChar As Integer, ByVal pintFundSearchChar As Integer, ByVal pblnIsSuggestionSearch As Boolean, ByVal penmInvSearchSummaryText As SearchSummaryText, ByVal penmFundSearchSummaryText As SearchSummaryText)
        Dim ldsDBSuggestions As DataSet = Nothing
        Dim lActiveRow As UltraGridRow
        Dim larrSuggestions As String() = {"Investors", "Funds"}
        Dim lintUniInvestorID As Integer
        Dim lintUniFundID As Integer
        Dim larrRow() As DataRow = Nothing
        Dim dv As DataView = Nothing
        Dim lblnIsActiveRowExtinct As Boolean
        Dim lintMappedInvestorID As Integer
        Dim lintMasterInvestorID As Integer
        Dim lstrQuery As String
        Dim lintTickedInvestorID As Integer
        Dim larrMappedRow() As DataRow
        Dim lintTickedRowIndexinMapData As Integer
        Dim lintTickedFundID As Integer
        Try
            ldsDBSuggestions = New DataSet
            'Store the Universal InvestorID so that universal mapping can appear in the result, if it's differnent from the client mapping
            If grdMapData.ActiveRow.GetCellValue("UniInvestorID").Equals(grdMapData.ActiveRow.GetCellValue("InvestorID")) OrElse _
                grdMapData.ActiveRow.GetCellValue("UniInvestorID") Is DBNull.Value Then
                lintUniInvestorID = 0
            Else
                lintUniInvestorID = grdMapData.ActiveRow.GetCellValue("UniInvestorID")
            End If

            'Store the Universal FundID so that universal mapping can appear in the result, if it's differnent from the client mapping
            If grdMapData.ActiveRow.GetCellValue("UniFundID").Equals(grdMapData.ActiveRow.GetCellValue("FundID")) OrElse _
                grdMapData.ActiveRow.GetCellValue("UniFundID") Is DBNull.Value Then
                lintUniFundID = 0
            Else
                lintUniFundID = grdMapData.ActiveRow.GetCellValue("UniFundID")
            End If

            'Check if the currently active investor in MapData is an Extinct; if it's extinct and used in a Merger OR Acquirer then the Parent Investor should come up as suggestion
            lblnIsActiveRowExtinct = False
            lintMappedInvestorID = 0
            lintMasterInvestorID = 0
            If grdMapData.ActiveRow.GetCellValue("InvStatusCode") IsNot DBNull.Value Then
                If grdMapData.ActiveRow.GetCellValue("InvStatusCode") = Crystal.CLL.EntityStatus.EXTNT.ToString Then
                    lblnIsActiveRowExtinct = True
                End If
            End If

            'Check if the currently active investor in MapData is already a Mapped Investor
            If grdMapData.ActiveRow.GetCellValue("InvestorID") IsNot DBNull.Value Then
                lintMappedInvestorID = grdMapData.ActiveRow.GetCellValue("InvestorID")
            End If

            'Conducting DB suggestions search
            'ldsDBSuggestions.Load(mclsImporteSourceManager.GetSuggestions(pstrInvestorSearch, pstrFundSearch, mintProjectID, lintUniInvestorID, lintUniFundID, pstrInvAddress, pstrFundAddress), LoadOption.OverwriteChanges, larrSuggestions)
            ldsDBSuggestions = mclsImporteSourceManager.GetSuggestions(pstrInvestorSearch, pstrFundSearch, mintProjectID, lintUniInvestorID, lintUniFundID, pstrInvAddress, _
                                                                       pstrFundAddress, lblnIsActiveRowExtinct, lintMappedInvestorID, lintMasterInvestorID, _
                                                                       mintCustodianInvestorID, pintInvestorSearchChar, pintFundSearchChar, pblnIsSuggestionSearch, _
                                                                       rdbInvNameContains.Checked, rdbInvAddressContains.Checked, rdbFundNameContains.Checked, _
                                                                       rdbFundAddressContains.Checked)
            If CommonCLL.CheckEmptyDataSet(ldsDBSuggestions) Then Exit Sub

            ldsDBSuggestions.Tables(0).TableName = "Investors"
            ldsDBSuggestions.Tables(1).TableName = "Funds"

            'If client mapping is different from universal mapping then, set it as first suggestion in the grid
            If lintUniInvestorID <> 0 Then
                lstrQuery = "InvestorID =" + lintUniInvestorID.ToString
                larrRow = ldsDBSuggestions.Tables("Investors").Select(lstrQuery)
                If larrRow.Length = 1 Then
                    larrRow(0).Item("Property") = mstrUniversal
                    larrRow(0).Item("UniRowIndex") = 1
                    larrRow(0).Item("Full Name") = grdMapData.ActiveRow.GetCellValue("UniFullName")
                End If
            End If

            'If current investor is extinct and is a part of Merger/Acquirer then it's Master Investor ID will be non-zero, hence set it as second suggestion in the grid
            If lintMasterInvestorID <> 0 Then
                lstrQuery = "InvestorID =" + lintMasterInvestorID.ToString
                larrRow = ldsDBSuggestions.Tables("Investors").Select(lstrQuery)
                'Dim ldrMasterInvestorRow As DataRow
                'ldrMasterInvestorRow = ldsDBSuggestions.Tables("Investors").NewRow
                If larrRow.Length = 1 Then
                    larrRow(0).Item("Property") = mstrMergedAcquired
                    larrRow(0).Item("MasterRowIndex") = 1
                End If
            End If

            'If universal investor id and the acquirer/merger investor id is same then set it's property accordingly
            If lintMasterInvestorID = lintUniInvestorID AndAlso lintMasterInvestorID <> 0 Then
                lstrQuery = "InvestorID =" + lintMasterInvestorID.ToString
                larrRow = ldsDBSuggestions.Tables("Investors").Select(lstrQuery)
                If larrRow.Length = 1 Then
                    larrRow(0).Item("Property") = mstrUniversalANDMergedAcquired
                    larrRow(0).Item("UniRowIndex") = 1
                    larrRow(0).Item("MasterRowIndex") = 1
                    larrRow(0).Item("Full Name") = grdMapData.ActiveRow.GetCellValue("UniFullName")
                End If
            End If

            'If client mapping is different from universal mapping then, set it as first suggestion in the grid
            If lintUniFundID <> 0 Then
                lstrQuery = "FundID =" + lintUniFundID.ToString
                larrRow = ldsDBSuggestions.Tables("Funds").Select(lstrQuery)
                If larrRow.Length > 0 Then
                    For Each lRow As DataRow In larrRow
                        lRow.Item("Property") = mstrUniversal
                        lRow.Item("UniRowIndex") = 1
                        lRow.Item("Full Name") = grdMapData.ActiveRow.GetCellValue("UniFullName")
                    Next
                End If
            End If

            If grdMapData.ActiveRow IsNot Nothing Then
                lActiveRow = grdMapData.ActiveRow

                'If the map data row is already mapped, Tick the respective Investor in Investor grid
                lintTickedInvestorID = -1
                If enmMappingType = MappingType.Excel OrElse enmMappingType = MappingType.Client Then
                    If lActiveRow.GetCellValue("InvestorID") IsNot DBNull.Value Then
                        lintTickedInvestorID = lActiveRow.GetCellValue("InvestorID")
                    End If
                ElseIf enmMappingType = MappingType.Universal Then
                    If lActiveRow.GetCellValue("UniInvestorID") IsNot DBNull.Value Then
                        lintTickedInvestorID = lActiveRow.GetCellValue("UniInvestorID")
                    End If
                End If

                If lintTickedInvestorID <> -1 Then

                    larrMappedRow = ldsDBSuggestions.Tables("Investors").Select("InvestorID ='" + lintTickedInvestorID.ToString + "'")
                    If larrMappedRow.Length = 1 Then
                        lintTickedRowIndexinMapData = ldsDBSuggestions.Tables("Investors").Rows.IndexOf(larrMappedRow(0))
                        ldsDBSuggestions.Tables("Investors").Rows(lintTickedRowIndexinMapData).Item("M") = True
                        ldsDBSuggestions.Tables("Investors").AcceptChanges()
                    End If
                End If

                'Sort to make universal mapping as first suggestion in the grid
                dv = New DataView(ldsDBSuggestions.Tables("Investors"))
                'dv.Sort = "M Desc, UniRowIndex Desc, MasterRowIndex Desc, Name Asc"
                dv.Sort = "M Desc, UniRowIndex Desc, MasterRowIndex Desc"

                grdInvestor.DataSource = dv.ToTable

                If ldsDBSuggestions.Tables("Investors").Rows.Count = 0 Then
                    If penmInvSearchSummaryText = SearchSummaryText.LessThanMin Then
                        ManageSuggestionsVisibility(True, False, False, grdInvestor, lblInvestorNoData, SearchSummaryText.LessThanMin)
                    Else
                        ManageSuggestionsVisibility(True, False, False, grdInvestor, lblInvestorNoData, SearchSummaryText.NoSuggestions)
                    End If
                Else
                    ManageSuggestionsVisibility(True, True, False, grdInvestor, lblInvestorNoData, SearchSummaryText.Found)
                    grdInvestor.Rows(0).Activated = True
                    grdInvestor.Rows(0).Cells("Name").Activated = True
                End If

                grdInvestor.Rows.Band.Columns("UniRowIndex").Hidden = True
                grdInvestor.Rows.Band.Columns("MasterRowIndex").Hidden = True
                grdInvestor.Rows.Band.Columns("Property").Hidden = True
                grdInvestor.Rows.Band.Columns("MInvestorTypeID").Hidden = True
                grdInvestor.Rows.Band.Columns("InvEntityID").Hidden = True
                grdInvestor.Rows.Band.Columns("InvestorID").Hidden = True
                grdInvestor.Rows.Band.Columns("InvStatusCode").Hidden = True
                grdInvestor.Rows.Band.Columns("M").Width = 10
                grdInvestor.Rows.Band.Columns("O").Width = 15
                grdInvestor.Rows.Band.Columns("Full Name").Width = 70
                grdInvestor.Rows.Band.Columns("Name").Width = 300

                'If the map data row is already mapped, Tick the respective fund in Fund grid

                If enmMappingType = MappingType.Excel OrElse enmMappingType = MappingType.Client Then
                    If lActiveRow.GetCellValue("FundID") IsNot DBNull.Value Then
                        lintTickedFundID = lActiveRow.GetCellValue("FundID")
                    End If
                ElseIf enmMappingType = MappingType.Universal Then
                    If lActiveRow.GetCellValue("UniFundID") IsNot DBNull.Value Then
                        lintTickedFundID = lActiveRow.GetCellValue("UniFundID")
                    End If
                End If
                If lintTickedFundID <> -1 Then
                    larrMappedRow = ldsDBSuggestions.Tables("Funds").Select("FundID='" + lintTickedFundID.ToString + "'")
                    If larrMappedRow.Length >= 1 Then
                        lintTickedRowIndexinMapData = ldsDBSuggestions.Tables("Funds").Rows.IndexOf(larrMappedRow(0))
                        ldsDBSuggestions.Tables("Funds").Rows(lintTickedRowIndexinMapData).Item("M") = True
                        ldsDBSuggestions.Tables("Funds").AcceptChanges()
                    End If
                End If

                'Sort to make universal mapping as first suggestion in the grid
                dv = New DataView(ldsDBSuggestions.Tables("Funds"))
                dv.Sort = "M Desc, UniRowIndex Desc"
                grdFund.DataSource = dv.ToTable

                If ldsDBSuggestions.Tables("Funds").Rows.Count = 0 Then
                    If penmFundSearchSummaryText = SearchSummaryText.NotValidForFunds Then
                        ManageSuggestionsVisibility(False, False, False, grdFund, lblFundNoData, SearchSummaryText.NotValidForFunds)
                    ElseIf penmFundSearchSummaryText = SearchSummaryText.LessThanMin Then
                        ManageSuggestionsVisibility(False, False, False, grdFund, lblFundNoData, SearchSummaryText.LessThanMin)
                    Else
                        ManageSuggestionsVisibility(False, False, False, grdFund, lblFundNoData, SearchSummaryText.NoSuggestions)
                    End If
                Else
                    ManageSuggestionsVisibility(False, True, False, grdFund, lblFundNoData, SearchSummaryText.Found)
                    grdFund.Rows(0).Activated = True
                    grdFund.Rows(0).Cells("Name").Activated = True
                End If

                grdFund.Rows.Band.Columns("UniRowIndex").Hidden = True
                grdFund.Rows.Band.Columns("Property").Hidden = True
                grdFund.Rows.Band.Columns("FundID").Hidden = True
                grdFund.Rows.Band.Columns("LinkCount").Hidden = True
                grdFund.Rows.Band.Columns("FundEntityID").Hidden = True
                grdFund.Rows.Band.Columns("FundStatusCode").Hidden = True
                grdFund.Rows.Band.Columns("InvestorID").Hidden = True
                grdFund.Rows.Band.Columns("MInvestorTypeID").Hidden = True
                grdFund.Rows.Band.Columns("InvStatusCode").Hidden = True
                grdFund.Rows.Band.Columns("InvEntityID").Hidden = True
                If grdFund.Rows.Band.Columns.Exists("LevenSort") Then
                    grdFund.Rows.Band.Columns("LevenSort").Hidden = True
                End If
                grdFund.Rows.Band.Columns("M").Width = 10
                grdFund.Rows.Band.Columns("O").Width = 15
                grdFund.Rows.Band.Columns("Full Name").Width = 70
                grdFund.Rows.Band.Columns("Name").Width = 300
            End If

        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            ldsDBSuggestions = Nothing
            lActiveRow = Nothing
            larrSuggestions = Nothing
            larrRow = Nothing
            dv = Nothing
        End Try
    End Sub

    Private Sub ManageSuggestionsVisibility(ByVal pblnIsInvestor As Boolean, ByVal pblnAreSuggestionsFound As Boolean, ByVal pblnIsLessThanMin As Boolean, _
                                            ByVal grdData As CrystalUltraGrid, ByVal lblMsg As CrystalLabel, ByVal penmSearchSummaryText As SearchSummaryText)
        If pblnAreSuggestionsFound Then
            grdData.Visible = True
            lblMsg.Visible = False
        Else
            If penmSearchSummaryText = SearchSummaryText.LessThanMin Then
                lblMsg.Text = MessageManager.GetMessage("EDS_MIN_SERCH_LEN", mintMinSearchLength.ToString)
            ElseIf penmSearchSummaryText = SearchSummaryText.NoSuggestions Then
                lblMsg.Text = MessageManager.GetMessage("EDS_NO_SUGGESTIONS_FOUND")
            ElseIf penmSearchSummaryText = SearchSummaryText.NotValidForFunds Then
                lblMsg.Text = MessageManager.GetMessage("EDS_NO_FND_SUGGESTIONS_FOR_INV")
            End If
            grdData.Visible = False
            lblMsg.Visible = True
        End If
    End Sub

    ''' <summary>
    ''' Conducts the Advanced Search, Filters the rows and Underlines the searched pharse
    ''' </summary>
    ''' <param name="pstrAdvancedSearch"></param>
    ''' <param name="pblnIsAll"></param>
    ''' <remarks></remarks>
    Private Sub ConductAdvancedFilter(ByVal pstrAdvancedSearch As String, ByVal pblnIsAll As Boolean)
        Dim strAccentedChar As String = CommonCLL.ReplaceForAccentedChars(pstrAdvancedSearch)
        FilterRows(strAccentedChar)
        FindAndUnderlinePhrase(grdMapData, strAccentedChar, pblnIsAll)
    End Sub

    ''' <summary>
    ''' To set the controls after filter selection
    ''' </summary>
    ''' <param name="pblnFromAll"></param>
    ''' <remarks></remarks>
    Private Sub SetControlsAfterFilterSelection(ByVal pblnFromAll As Boolean)
        Dim rootBand As UltraGridBand
        Try
            If grdMapData.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False Then
                grdMapData.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.True
            End If
            rootBand = grdMapData.DisplayLayout.Bands(0)
            rootBand.ColumnFilters.ClearAllFilters()

            If pblnFromAll Then
                If btnAdvanceFilter.Visible = False Then
                    btnAdvanceFilter.Visible = True
                End If
            Else
                If btnAdvanceFilter.Visible Then
                    btnAdvanceFilter.Visible = False
                End If
            End If
            If lblAdvancedSearchText.Visible Then
                lblAdvancedSearchText.Visible = False
                lblAdvancedSearchValue.Visible = False
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            rootBand = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' To set the cells' formatting to normal
    ''' </summary>
    ''' <param name="lRow"></param>
    ''' <remarks></remarks>
    Private Sub SetAdvancedSearchFormattingToNormal(ByVal lRow As UltraGridRow)
        If lRow.IsFilteredOut = False Then
            For Each lCell As UltraGridCell In lRow.Cells
                If marrExcludedFromFilters.Contains(lCell.Column.Header.Caption) Then Continue For
                lCell.Appearance.BorderColor = Color.Silver
                lCell.Appearance.FontData.Underline = Infragistics.Win.DefaultableBoolean.False
            Next
        End If
    End Sub

    ''' <summary>
    ''' To save the snapshot and control's status
    ''' </summary>
    ''' <param name="pintRegularRadio"></param>
    ''' <param name="pblnRetail"></param>
    ''' <param name="pblnCustodian"></param>
    ''' <param name="pblnCreateNew"></param>
    ''' <param name="pintAdvancedRadio"></param>
    ''' <param name="pintRowNumber"></param>
    ''' <param name="pblnIsCompleted"></param>
    ''' <remarks></remarks>
    Private Function SaveSnapshot(ByVal pintRegularRadio As Int16, ByVal pblnRetail As Boolean, ByVal pblnCustodian As Boolean, ByVal pblnCreateNew As Boolean, _
                                  ByVal pintAdvancedRadio As Int16, ByVal pintRowNumber As Integer, ByVal pblnIsCompleted As Boolean) As Boolean
        Dim lstrOldFolderPath As String = ""
        Dim lstrHiddenColumns As String = ""
        'Dim ExpToExcel As UltraGridExcelExporter = Nothing
        Dim ExcWorkbook As Workbook = Nothing
        Dim lstrDateTime As String
        Dim lstrFilePath As String
        Dim lobjws As Worksheet
        Dim lblnHasAnyDoubt As Boolean
        Try
            If mstrEDSSnapshotPath.Equals("") Then
                Me.ShowMessageBox(DBResult.FOLDER_NOTACCESS, BaseClass.Capitalize("eSource Import"))
                Return False
            End If
            lstrDateTime = DateTime.Now.ToString()
            lstrDateTime = lstrDateTime.Replace(":", "_").Replace("/", "_")
            'Get the already saved snapshot path
            lstrOldFolderPath = mclsImporteSourceManager.GetSnapshotFilePath(mintEntityID)
            lstrFilePath = mstrEDSSnapshotPath + "\" + mstrClientName + " - " + mstrProjectName + " - EDS - " & mstrDataSourceName & " " & mstrListingName & " - " & mintEntityID & " - " & lstrDateTime & ".xlsx"
            'lstrFilePath = lstrFilePath.Replace(":", "_").Replace("/", "_")
            'ExpToExcel = New UltraGridExcelExporter()
            ExcWorkbook = New Workbook(WorkbookFormat.Excel2007, WorkbookPaletteMode.CustomPalette)
            lobjws = ExcWorkbook.Worksheets.Add(mstrSourceName)
            ' ''Unhide the columns so that all columns can be saved in the snapshot
            For Each lCol As UltraGridColumn In grdMapData.DisplayLayout.Bands(0).Columns
                If lCol.Hidden Then
                    lstrHiddenColumns += lCol.Header.Caption + "~"
                    'lCol.Hidden = False
                End If
            Next

            'Unhide the rows so that all rows can be saved in the snapshot
            lblnHasAnyDoubt = False
            For Each lRow As UltraGridRow In grdMapData.Rows
                If lRow.GetCellValue("Doubts") = True AndAlso lblnHasAnyDoubt = False Then
                    lblnHasAnyDoubt = True
                End If
                If lRow.Hidden Then
                    lRow.Hidden = False
                End If
            Next
            mclsImporteSourceManager.ManageEntityDoubtStatus(mintEntityID, lblnHasAnyDoubt)
            'grdMapData.DisplayLayout.Bands(0).ColumnFilters.ClearAllFilters()
            rdAll.Checked = True
            pintAdvancedRadio = 1
            CallAllMapDataRecords()
            lstrHiddenColumns.TrimEnd("~")
            UltraGridExcelExporter1.Export(grdMapData, lobjws, 0, 0)
            'ExpToExcel.Export(grdMapData, lobjws, 0, 0)
            'Save the snapshot
            ExcWorkbook.Save(lstrFilePath)
            ''Hide the columns that were made visible before saving the file
            'For Each lCol As String In lstrHiddenColumns.Split("~")
            '    If grdMapData.DisplayLayout.Bands(0).Columns.Exists(lCol) Then
            '        grdMapData.DisplayLayout.Bands(0).Columns(lCol).Hidden = True
            '    End If
            'Next
            'Updates the statues in the database
            mclsImporteSourceManager.InsertUpdateESourceSnapshot(mintEntityID, lstrFilePath, pintRegularRadio, pblnRetail, pblnCustodian, pblnCreateNew, pintAdvancedRadio, pintRowNumber, CommonCLL.UserID, pblnIsCompleted, mintTemplateID, lstrHiddenColumns, mintProjectID)
            'Delete the old file
            If lstrOldFolderPath IsNot Nothing Then
                If lstrOldFolderPath.Equals("") = False AndAlso IO.File.Exists(lstrOldFolderPath) Then
                    Dim lstrFileName As String = System.IO.Path.GetFileName(lstrOldFolderPath)
                    Dim lstrArchieveFilePath As String = mstrEDSSnapshotPathArchieve + "\" + lstrFileName
                    System.IO.File.Move(lstrOldFolderPath, lstrArchieveFilePath)
                    'System.IO.File.Delete(lstrOldFolderPath)
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
            Return False
        Finally
            'ExpToExcel = Nothing
            ExcWorkbook = Nothing
        End Try
        Return True
    End Function

    Private Sub ShowContextMenu(ByVal mousePoint As Point)
        cMenu.Show(grdMapData, mousePoint)
    End Sub

    ''' <summary>
    ''' To restore original mappings
    ''' </summary>
    ''' <param name="pstrOriginalItem"></param>
    ''' <param name="pstrItem"></param>
    ''' <param name="pblnIsInvestor"></param>
    ''' <param name="grdData"></param>
    ''' <remarks></remarks>
    Private Sub RestoreOriginalMappings(ByVal pstrOriginalItem As String, ByVal pstrItem As String, ByVal pblnIsInvestor As Boolean, ByVal grdData As CrystalUltraGrid)
        Dim lblnZeroIsSelectedRow As Boolean = False
        Dim ldtAttributes As DataTable = Nothing
        Dim lstrQuery As String
        Dim larrRow() As DataRow
        Dim larrMappedCol() As DataRow

        Try
            ldtAttributes = New DataTable
            'To select the active row, if selected rows are 0
            If grdMapData.Selected.Rows.Count = 0 Then
                lblnZeroIsSelectedRow = True
                grdMapData.Rows(grdMapData.ActiveRow.Index).Selected = True
            End If

            'Get the other attributes of the selected records
            ldtAttributes = GetOtherAttributes(pstrOriginalItem, pstrOriginalItem, pblnIsInvestor)

            'Restore the mapping and set other attributes
            For Each lRow As UltraGridRow In grdMapData.Selected.Rows
                'If lRow.Cells(pstrOriginalItem).Value Is DBNull.Value Then Continue For
                If lRow.GetCellValue(pstrOriginalItem).Equals(lRow.GetCellValue(pstrItem)) Then Continue For
                If lRow.GetCellValue(pstrOriginalItem) Is DBNull.Value Then
                    If pblnIsInvestor Then
                        SetInvestorRelatedFields(lRow, Nothing, Nothing, InvestorMappingChangesSource.Restore)
                        'lRow.Cells(mstrMappedInvName).Value = ""
                        'lRow.Cells("InvestorID").Value = DBNull.Value
                        'lRow.Cells("MInvestorTypeID").Value = DBNull.Value
                        'lRow.Cells("InvStatusCode").Value = ""
                        'lRow.Cells("InvEntityID").Value = ""
                    Else
                        SetFundRelatedFields(lRow, Nothing, Nothing, FundMappingChangesSource.Restore)
                        'lRow.Cells(mstrMappedFundName).Value = ""
                        'lRow.Cells("FundID").Value = DBNull.Value
                        'lRow.Cells("FundStatusCode").Value = ""
                        'lRow.Cells("LinkCount").Value = 0
                        'lRow.Cells("FundEntityID").Value = ""
                    End If
                Else
                    lstrQuery = pstrItem + " =" + lRow.GetCellValue(pstrOriginalItem).ToString
                    larrRow = ldtAttributes.Select(lstrQuery)
                    If larrRow.Length = 1 Then
                        If pblnIsInvestor Then
                            SetInvestorRelatedFields(lRow, larrRow(0), Nothing, InvestorMappingChangesSource.Restore)
                            'lRow.Cells(mstrMappedInvName).Value = larrRow(0).Item("InvestorName")
                            'lRow.Cells("InvestorID").Value = larrRow(0).Item("InvestorID")
                            'lRow.Cells("MInvestorTypeID").Value = larrRow(0).Item("MInvestorTypeID")
                            'lRow.Cells("InvStatusCode").Value = larrRow(0).Item("InvStatusCode")
                            'lRow.Cells("InvEntityID").Value = larrRow(0).Item("InvEntityID")
                        Else
                            SetFundRelatedFields(lRow, larrRow(0), Nothing, FundMappingChangesSource.Restore)
                            'lRow.Cells(mstrMappedFundName).Value = larrRow(0).Item("FundName")
                            'lRow.Cells("FundID").Value = larrRow(0).Item("FundID")
                            'lRow.Cells("FundStatusCode").Value = larrRow(0).Item("FundStatusCode")
                            'lRow.Cells("LinkCount").Value = larrRow(0).Item("LinkCount")
                            'lRow.Cells("FundEntityID").Value = larrRow(0).Item("FundEntityID")
                        End If
                    End If
                End If
                'lRow.Cells("UserID").Value = CommonCLL.UserID
                'lRow.Cells("Full Name").Value = CommonCLL.UserFullName
            Next

            'To untick the ticked investor/fund in the Investor/Fund grid, if any; so that original mapping can get ticked
            If grdMapData.ActiveRow IsNot Nothing Then
                If grdData.DataSource IsNot Nothing Then
                    'Un-Tick other rows in the grid
                    larrMappedCol = CType(grdData.DataSource, DataTable).Select("M=True")
                    If larrMappedCol.Length > 0 Then
                        For Each lRow As DataRow In larrMappedCol
                            lRow.Item("M") = False
                        Next
                    End If
                    'Tick the original mapping
                    If grdMapData.ActiveRow.GetCellValue(pstrItem) IsNot DBNull.Value Then
                        lstrQuery = pstrItem + " =" + grdMapData.ActiveRow.GetCellValue(pstrItem).ToString
                        larrRow = CType(grdData.DataSource, DataTable).Select(lstrQuery)
                        If larrRow.Length > 0 Then
                            grdData.Rows(CType(grdData.DataSource, DataTable).Rows.IndexOf(larrRow(0))).Cells("M").Value = True
                        End If
                    End If
                    grdData.UpdateData()
                End If
            End If

            'Unselect the selected row, if the select count was 0
            If lblnZeroIsSelectedRow Then
                grdMapData.Rows(grdMapData.ActiveRow.Index).Selected = False
            End If
            grdMapData.UpdateData()
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            ldtAttributes = Nothing
            larrRow = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' To set the doubt status
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SetDoubtStatusForMapData()
        'Tick/Un-Tick funcationality
        For Each lRow As UltraGridRow In grdMapData.Selected.Rows
            If (lRow.GetCellValue("Doubts") = True) Then
                lRow.Cells("Doubts").Value = False
            Else
                'Tick the selected/active row
                lRow.Cells("Doubts").Value = True
            End If
            'CType(grdMapData.DataSource, DataTable).AcceptChanges()
        Next
        grdMapData.UpdateData()
    End Sub

    ''' <summary>
    ''' To get other attributes(MInvestorType,StatusCode,EntityID) of the searched rows
    ''' </summary>
    ''' <param name="lstrColName"></param>
    ''' <param name="lstrFunctionColName"></param>
    ''' <param name="lblnIsInvestor"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetOtherAttributes(ByVal lstrColName As String, ByVal lstrFunctionColName As String, ByVal lblnIsInvestor As Boolean) As DataTable
        Dim ldtDataList As DataTable = Nothing
        Dim ldrDataList As DataRow = Nothing
        Dim lstrData As String
        Try
            ldtDataList = New DataTable
            ldtDataList.Columns.Add("DataListID", GetType(String))
            'Store IDs
            For Each lRow As UltraGridRow In grdMapData.Selected.Rows
                If lRow.GetCellValue(lstrColName) Is DBNull.Value Then Continue For
                ldrDataList = ldtDataList.NewRow
                ldrDataList.Item("DataListID") = lRow.GetCellValue(lstrFunctionColName)
                ldtDataList.Rows.Add(ldrDataList)
            Next
            'Get data in string
            lstrData = CommonCLL.GetXMlFromDataTable(ldtDataList, {""})
            Return mclsImporteSourceManager.GetOtherAttributes(lstrData, lblnIsInvestor, mintProjectID)
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
            Return Nothing
        Finally
            ldtDataList = Nothing
            ldrDataList = Nothing
        End Try
    End Function

    ''' <summary>
    ''' To select the next matched pharse in the MapData grid
    ''' </summary>
    ''' <param name="grdData"></param>
    ''' <param name="lintActiveRowIndex"></param>
    ''' <remarks></remarks>
    Private Sub SelectNextPhraseOccurance(ByVal grdData As Crystal.CustomControls.CrystalUltraGrid, ByVal lintActiveRowIndex As Integer, ByVal pstrSearchText As String)
        If grdData.ActiveRow Is Nothing OrElse grdMapData.Rows.FilteredInRowCount = 0 Then Exit Sub
        Dim lblnIsFoundInCurrent = False
        Dim lintCurrentCellIndex As Integer
        Dim lintActiveRowIndexBackup As Integer = lintActiveRowIndex
        Dim lblnAnyMatchFound As Boolean = False
        Dim lenmRegularSearchOperator As FilterLogicalOperator
        Dim lblnIsTwoText As Boolean = False
        Dim lblnSuccess As Boolean
        Dim lstrSearch() As String = Nothing
        Dim lstrCellData As String
        Try
            If grdData.ActiveCell Is Nothing Then
                grdData.ActiveRow.Cells(0).Activated = True
            Else
                lintCurrentCellIndex = grdData.ActiveCell.Column.Index + 1
            End If
            pstrSearchText = CommonCLL.ReplaceRegexMetaChars(mstrSearchText)

            'Set the SearchOperaator and See if its TwoText
            lblnIsTwoText = False
            If pstrSearchText.Contains(mstrANDOperator) Then
                lenmRegularSearchOperator = FilterLogicalOperator.And
                lblnIsTwoText = True
            ElseIf pstrSearchText.Contains(mstrOROperator) Then
                lenmRegularSearchOperator = FilterLogicalOperator.Or
                lblnIsTwoText = True
            End If

            'Set the SearchType
            If pstrSearchText.Trim = "" Then
                enmSearchTypes = SearchTypes.Blank
            ElseIf lblnIsTwoText Then
                enmSearchTypes = SearchTypes.DoubleText
            Else
                enmSearchTypes = SearchTypes.SingleText
            End If

            lblnSuccess = False

            If enmSearchTypes = SearchTypes.DoubleText Then
                If lenmRegularSearchOperator = FilterLogicalOperator.And Then
                    'strText = "[" + strText.Replace(mstrANDOperator, "") + "]"
                    lstrSearch = pstrSearchText.Split(mstrANDOperator)
                Else
                    'strText = "[" + strText.Replace(mstrOROperator, "") + "]"
                    lstrSearch = pstrSearchText.Split(mstrOROperator)
                End If
                'See if its Begins With
                If rdBeginsWith.Checked Then
                    lstrSearch(0) = "^" + lstrSearch(0)
                    lstrSearch(1) = "^" + lstrSearch(1)
                End If
                'If its SingleText and Beigns With
            ElseIf enmSearchTypes = SearchTypes.SingleText AndAlso rdBeginsWith.Checked Then
                pstrSearchText = "^" + pstrSearchText
            End If
            'pstrSearchText = "[^c[eèéëêËÈÉÊ][nñÑ]^21]"


            'Traverse starting from the current row to end
            While lintActiveRowIndex < grdData.Rows.Count
                'Ignore if the row is filtered out
                If grdData.Rows(lintActiveRowIndex).IsFilteredOut = False Then
                    'Starting from the current column to the last, check if there is any cell with underligned font i.e. matched pharse
                    For value As Integer = lintCurrentCellIndex To grdMapData.Rows.Band.Columns.Count - 1
                        If marrExcludedFromFilters.Contains(grdMapData.Rows.Band.Columns(value).Header.Caption) Then Continue For
                        If grdData.Rows(lintActiveRowIndex).GetCellValue(grdMapData.Rows.Band.Columns(value)) Is DBNull.Value Then Continue For
                        lstrCellData = grdData.Rows(lintActiveRowIndex).GetCellValue(grdMapData.Rows.Band.Columns(value)).ToString
                        'If its blank, compare with =
                        If enmSearchTypes = SearchTypes.Blank Then
                            If lstrCellData = pstrSearchText Then
                                lblnSuccess = True
                            Else
                                lblnSuccess = False
                            End If
                        Else
                            'If its DoubleText Or SingleText, compare with Match
                            If enmSearchTypes = SearchTypes.DoubleText Then
                                If lenmRegularSearchOperator = FilterLogicalOperator.And Then
                                    If Regex.Match(lstrCellData, lstrSearch(0), RegexOptions.IgnoreCase).Success AndAlso Regex.Match(lstrCellData, lstrSearch(1), RegexOptions.IgnoreCase).Success Then
                                        lblnSuccess = True
                                    Else
                                        lblnSuccess = False
                                    End If
                                Else
                                    If Regex.Match(lstrCellData, lstrSearch(0), RegexOptions.IgnoreCase).Success OrElse Regex.Match(lstrCellData, lstrSearch(1), RegexOptions.IgnoreCase).Success Then
                                        lblnSuccess = True
                                    Else
                                        lblnSuccess = False
                                    End If
                                End If
                            Else
                                If Regex.Match(lstrCellData, pstrSearchText, RegexOptions.IgnoreCase).Success Then
                                    lblnSuccess = True
                                Else
                                    lblnSuccess = False
                                End If
                            End If
                            'If found, unselect the currently selected cell and select the found cell
                            If lblnSuccess Then
                                lblnAnyMatchFound = True
                                If grdData.Selected.Cells.Count > 0 Then
                                    grdData.Selected.Cells(0).Selected = False
                                End If
                                grdData.ActiveCell.Activated = False
                                'Make the found cell as active
                                'grdData.Rows(lintActiveRowIndex).VisibleIndex
                                If CommonCLL.IsRowVisible(grdData, grdData.Rows(lintActiveRowIndex)) = False Then
                                    CommonCLL.ScrollRowToMiddle(grdData.Rows(lintActiveRowIndex))
                                End If
                                grdData.Rows(lintActiveRowIndex).Cells(value).Activated = True
                                grdData.DisplayLayout.ColScrollRegions(0).ScrollColIntoView(grdData.ActiveCell.Column)
                                'Set the boolean variable that it's found in the currently active row
                                lblnIsFoundInCurrent = True
                                Exit While
                            End If
                        End If
                    Next
                End If
                lintCurrentCellIndex = 0
                lintActiveRowIndex += 1
            End While
            'Recall the procedure with the next row, if the pharse not found in the currently active row and also if grid has not reached to its end
            If lblnIsFoundInCurrent = False AndAlso lintActiveRowIndex <> grdData.Rows.Count Then
                SelectNextPhraseOccurance(grdData, grdMapData.ActiveRow.Index + 1, mstrSearchText)
            End If
            'If reached the last row, then restart from the first
            If lintActiveRowIndexBackup = 0 AndAlso lblnAnyMatchFound = False Then
            Else
                If lintActiveRowIndex = grdData.Rows.Count Then
                    SelectNextPhraseOccurance(grdData, 0, mstrSearchText)
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        End Try
    End Sub

    'Private Sub SelectNextPhraseOccurance(ByVal grdData As Crystal.CustomControls.CrystalUltraGrid, ByVal lintActiveRowIndex As Integer)
    '    If grdData.ActiveRow Is Nothing OrElse grdMapData.Rows.FilteredInRowCount = 0 Then Exit Sub
    '    Dim lblnIsFoundInCurrent = False
    '    Dim lintCurrentCellIndex As Integer
    '    Dim lintActiveRowIndexBackup As Integer = lintActiveRowIndex
    '    Dim lblnAnyMatchFound As Boolean = False
    '    Dim lenmRegularSearchOperator As FilterLogicalOperator
    '    Try
    '        If grdData.ActiveCell Is Nothing Then
    '            grdData.ActiveRow.Cells(0).Activated = True
    '        Else
    '            lintCurrentCellIndex = grdData.ActiveCell.Column.Index + 1
    '        End If

    '        'If mstrSearchText.Contains("|") Then
    '        '    mstrSearchText = mstrSearchText.Replace("|", "\|")
    '        'End If
    '        'Set the SearchOperaator and See if its TwoText
    '        Dim lblnIsTwoText As Boolean = False
    '        If mstrSearchText.Contains(mstrANDOperator) Then
    '            lenmRegularSearchOperator = FilterLogicalOperator.And
    '            lblnIsTwoText = True
    '        ElseIf mstrSearchText.Contains(mstrOROperator) Then
    '            lenmRegularSearchOperator = FilterLogicalOperator.Or
    '            lblnIsTwoText = True
    '        End If

    '        'Set the SearchType
    '        If mstrSearchText.Trim = "" Then
    '            enmSearchTypes = SearchTypes.Blank
    '        ElseIf lblnIsTwoText Then
    '            enmSearchTypes = SearchTypes.DoubleText
    '        Else
    '            enmSearchTypes = SearchTypes.SingleText
    '        End If

    '        Dim lblnSuccess As Boolean = False
    '        Dim lstrSearch() As String = Nothing
    '        If enmSearchTypes = SearchTypes.DoubleText Then
    '            If lenmRegularSearchOperator = FilterLogicalOperator.And Then
    '                'strText = "[" + strText.Replace(mstrANDOperator, "") + "]"
    '                lstrSearch = mstrSearchText.Split(mstrANDOperator)
    '            Else
    '                'strText = "[" + strText.Replace(mstrOROperator, "") + "]"
    '                lstrSearch = mstrSearchText.Split(mstrOROperator)
    '            End If
    '            'See if its Begins With
    '            If rdBeginsWith.Checked Then
    '                lstrSearch(0) = "^" + lstrSearch(0)
    '                lstrSearch(1) = "^" + lstrSearch(1)
    '            End If
    '            'If its SingleText and Beigns With
    '        ElseIf enmSearchTypes = SearchTypes.SingleText AndAlso rdBeginsWith.Checked Then
    '            mstrSearchText = "^" + mstrSearchText
    '        End If
    '        'mstrSearchText = "[^c[eèéëêËÈÉÊ][nñÑ]^21]"

    '        Dim lstrCellData As String

    '        'Traverse starting from the current row to end
    '        While lintActiveRowIndex < grdData.Rows.Count
    '            'Ignore if the row is filtered out
    '            If grdData.Rows(lintActiveRowIndex).IsFilteredOut = False Then
    '                'Starting from the current column to the last, check if there is any cell with underligned font i.e. matched pharse
    '                For value As Integer = lintCurrentCellIndex To grdMapData.Rows.Band.Columns.Count - 1
    '                    If grdData.Rows(lintActiveRowIndex).Cells(value).Value Is DBNull.Value Then Continue For
    '                    lstrCellData = grdData.Rows(lintActiveRowIndex).Cells(value).Value.ToString
    '                    'If its blank, compare with =
    '                    If enmSearchTypes = SearchTypes.Blank Then
    '                        If lstrCellData = mstrSearchText Then
    '                            lblnSuccess = True
    '                        Else
    '                            lblnSuccess = False
    '                        End If
    '                    Else
    '                        'If its DoubleText Or SingleText, compare with Match
    '                        If enmSearchTypes = SearchTypes.DoubleText Then
    '                            If lenmRegularSearchOperator = FilterLogicalOperator.And Then
    '                                If Regex.Match(lstrCellData, lstrSearch(0), RegexOptions.IgnoreCase).Success AndAlso Regex.Match(lstrCellData, lstrSearch(1), RegexOptions.IgnoreCase).Success Then
    '                                    lblnSuccess = True
    '                                Else
    '                                    lblnSuccess = False
    '                                End If
    '                            Else
    '                                If Regex.Match(lstrCellData, lstrSearch(0), RegexOptions.IgnoreCase).Success OrElse Regex.Match(lstrCellData, lstrSearch(1), RegexOptions.IgnoreCase).Success Then
    '                                    lblnSuccess = True
    '                                Else
    '                                    lblnSuccess = False
    '                                End If
    '                            End If
    '                        Else
    '                            If Regex.Match(lstrCellData, mstrSearchText, RegexOptions.IgnoreCase).Success Then
    '                                lblnSuccess = True
    '                            Else
    '                                lblnSuccess = False
    '                            End If
    '                        End If
    '                        'If found, unselect the currently selected cell and select the found cell
    '                        If lblnSuccess Then
    '                            lblnAnyMatchFound = True
    '                            If grdData.Selected.Cells.Count > 0 Then
    '                                grdData.Selected.Cells(0).Selected = False
    '                            End If
    '                            grdData.ActiveCell.Activated = False
    '                            'Make the found cell as active
    '                            grdData.Rows(lintActiveRowIndex).Cells(value).Activated = True
    '                            'Set the boolean variable that it's found in the currently active row
    '                            lblnIsFoundInCurrent = True
    '                            Exit While
    '                        End If
    '                    End If
    '                Next
    '            End If
    '            lintCurrentCellIndex = 0
    '            lintActiveRowIndex += 1
    '        End While
    '        'Recall the procedure with the next row, if the pharse not found in the currently active row and also if grid has not reached to its end
    '        If lblnIsFoundInCurrent = False AndAlso lintActiveRowIndex <> grdData.Rows.Count Then
    '            SelectNextPhraseOccurance(grdData, grdMapData.ActiveRow.Index + 1)
    '        End If
    '        'If reached the last row, then restart from the first
    '        If lintActiveRowIndexBackup = 0 AndAlso lblnAnyMatchFound = False Then
    '        Else
    '            If lintActiveRowIndex = grdData.Rows.Count Then
    '                SelectNextPhraseOccurance(grdData, 0)
    '            End If
    '        End If
    '    Catch ex As Exception
    '        Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
    '    End Try
    'End Sub


    ''' <summary>
    ''' To conduct the suggestion search
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub ConductSuggestionSearch()
        Dim lstrInvestorSearch As StringBuilder = Nothing
        Dim lstrFundSearch As StringBuilder = Nothing
        Dim lblnIsInvestorRow As Boolean = False
        Dim lenmInvSearchSummaryText As SearchSummaryText = SearchSummaryText.Found
        Dim lenmFundSearchSummaryText As SearchSummaryText = SearchSummaryText.Found
        Dim lActiveRow As UltraGridRow
        Try
            lstrInvestorSearch = New StringBuilder
            lstrFundSearch = New StringBuilder
            If grdMapData.ActiveRow Is Nothing Then
                Me.ShowMessageBox(DBResult.EDS_MPNG_SEL_ROW)
                Exit Sub
            End If

            If cmbInvestorField.SelectedItem IsNot Nothing Then
                If Convert.ToInt32(txtInvSearchChar.Text) < mintMinSearchLength Then
                    'If Convert.ToInt32(txtInvSearchChar.Text) <= Convert.ToInt32(Math.Ceiling((grdMapData.ActiveRow.Cells(cmbInvestorField.SelectedItem("FieldName")).Value.ToString.Trim.Length * mintInvestorMinSearchPercentage) / 100)) Then
                    lenmInvSearchSummaryText = SearchSummaryText.LessThanMin
                    'ManageSuggestionsVisibility(True, False, True, grdInvestor, lblInvestorNoData, lenmInvSearchSummaryText)

                    'lblInvestorNoData.Text = MessageManager.GetMessage("EDS_INV_MIN_SERCH_LEN")
                    'lblInvestorNoData.Appearance.FontData.SizeInPoints = 12
                    'ShowMessageBox(DBResult.EDS_INV_MIN_SERCH_LEN, mintInvestorMinSearchPercentage.ToString)
                    'Exit Sub
                End If
            End If

            'Check, If it's an Investor row in Public, if so then don't run character length validation on Fund field.
            If menmSourceTypeCode = SourceTypeCode.PBC Then
                If grdMapData.ActiveRow.GetCellValue(mstrMatchCol4).ToString.Equals("") Then
                    lenmFundSearchSummaryText = SearchSummaryText.NotValidForFunds
                    'ManageSuggestionsVisibility(True, False, True, grdInvestor, lblInvestorNoData, lenmInvSearchSummaryText)

                    lblnIsInvestorRow = True
                End If
            End If

            If cmbFundField.SelectedItem IsNot Nothing AndAlso lblnIsInvestorRow = False Then
                If txtFundSearchChar.Text < mintMinSearchLength Then
                    'If txtFundSearchChar.Text <= Math.Round((grdMapData.ActiveRow.Cells(cmbFundField.SelectedItem("FieldName")).Value.ToString.Trim.Length * mintFundMinSearchPercentage) / 100) Then
                    lenmFundSearchSummaryText = SearchSummaryText.LessThanMin
                    'ManageSuggestionsVisibility(False, False, True, grdFund, lblFundNoData, lenmFundSearchSummaryText)

                    'ShowMessageBox(DBResult.EDS_FND_MIN_SERCH_LEN, mintFundMinSearchPercentage.ToString)
                    'Exit Sub
                End If
            End If

            'If the Investor search text length is less than minimum or if the currently selected row is Investor andalso if the fund search text length is less than minimum then don't conduct the search.
            If lenmInvSearchSummaryText = SearchSummaryText.LessThanMin AndAlso (lenmFundSearchSummaryText = SearchSummaryText.NotValidForFunds OrElse lenmFundSearchSummaryText = SearchSummaryText.LessThanMin) Then
                ManageSuggestionsVisibility(True, False, True, grdInvestor, lblInvestorNoData, lenmInvSearchSummaryText)
                ManageSuggestionsVisibility(False, False, True, grdFund, lblFundNoData, lenmFundSearchSummaryText)
                grdMapData.Focus()
                Exit Sub
            End If

            'Formulate the Investor and Fund search text
            lActiveRow = grdMapData.ActiveRow
            'Formulate investor search text for DB suggestions
            If cmbInvestorField.SelectedItem Is Nothing OrElse (lenmInvSearchSummaryText = SearchSummaryText.LessThanMin OrElse lenmInvSearchSummaryText = SearchSummaryText.NotValidForFunds) Then
                lstrInvestorSearch.Append("")
            Else
                lstrInvestorSearch.Append(lActiveRow.Cells(cmbInvestorField.SelectedItem("FieldName")).Text.ToString.Trim)
            End If

            'Formulate fund search text for DB suggestions
            If cmbFundField.SelectedItem Is Nothing OrElse lenmFundSearchSummaryText = SearchSummaryText.LessThanMin Then
                lstrFundSearch.Append("")
            Else
                lstrFundSearch.Append(lActiveRow.Cells(cmbFundField.SelectedItem("FieldName")).Text.ToString.Trim)
            End If

            'If MessageManager.GetMessage("EDS_INVNAME_SEARCH") <> txtInvestor.Text Then
            '    SetDefaulInvestorSearchText()
            'End If
            'If MessageManager.GetMessage("EDS_FUNDNAME_SEARCH") <> txtFund.Text Then
            '    SetDefaulFundSearchText()
            'End If
            If MessageManager.GetMessage("EDS_ADD_SEARCH") <> txtInvAddress.Text Then
                SetDefaulInvAddressSearchText()
            End If
            If MessageManager.GetMessage("EDS_ADD_SEARCH") <> txtFundAddress.Text Then
                SetDefaulFundAddressSearchText()
            End If
            ConductSearch(lstrInvestorSearch.ToString, lstrFundSearch.ToString, "", "", txtInvSearchChar.Text, txtFundSearchChar.Text, True, lenmInvSearchSummaryText, lenmFundSearchSummaryText)
            'Tick/Un-tick custodian check box, if the current row is marked as Custodian
            If lActiveRow.GetCellValue("InvestorID") IsNot DBNull.Value Then
                If lActiveRow.GetCellValue("InvestorID") = mintCustodianInvestorID Then
                    chkMarkCustodian.Checked = True
                Else
                    chkMarkCustodian.Checked = False
                End If
            Else
                chkMarkCustodian.Checked = False
            End If

            'Tick/Un-tick Create New Investor check box, if the current row is marked as Create New Investor
            If lActiveRow.GetCellValue("InvestorID") Is DBNull.Value Then
                If lActiveRow.GetCellValue(mstrMappedInvName).ToString = mstrCreateNew Then
                    chkCreateNewInv.Checked = True
                Else
                    chkCreateNewInv.Checked = False
                End If
            Else
                chkCreateNewInv.Checked = False
            End If

            'Tick/Un-tick Create New Fund check box, if the current row is marked as Create New Fund
            If lActiveRow.GetCellValue("FundID") Is DBNull.Value Then
                If lActiveRow.GetCellValue(mstrMappedFundName).ToString = mstrCreateNew Then
                    chkCreateNewFund.Checked = True
                Else
                    chkCreateNewFund.Checked = False
                End If
            Else
                chkCreateNewFund.Checked = False
            End If

        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            lstrInvestorSearch = Nothing
            lstrFundSearch = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' To conduct the advanced search
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub ConductAdvancedSearch()
        Dim lstrInvestorSearch As String
        Dim lstrFundSearch As String
        Dim lstrInvAddressSearch As String
        Dim lstrFundAddressSearch As String

        'Prepare the search text
        If MessageManager.GetMessage("EDS_INVNAME_SEARCH") = txtInvestor.Text Then
            lstrInvestorSearch = ""
        Else
            lstrInvestorSearch = txtInvestor.Text
        End If

        If MessageManager.GetMessage("EDS_FUNDNAME_SEARCH") = txtFund.Text Then
            lstrFundSearch = ""
        Else
            lstrFundSearch = txtFund.Text
        End If

        If MessageManager.GetMessage("EDS_ADD_SEARCH") = txtInvAddress.Text Then
            lstrInvAddressSearch = ""
        Else
            lstrInvAddressSearch = txtInvAddress.Text
        End If

        If MessageManager.GetMessage("EDS_ADD_SEARCH") = txtFundAddress.Text Then
            lstrFundAddressSearch = ""
        Else
            lstrFundAddressSearch = txtFundAddress.Text
        End If

        Dim lenmFundSearchSummaryText As SearchSummaryText = SearchSummaryText.NoSuggestions
        'Check, If it's an Investor row in Public, if so then don't run character length validation on Fund field.
        If menmSourceTypeCode = SourceTypeCode.PBC Then
            If grdMapData.ActiveRow.GetCellValue(mstrMatchCol4).ToString.Equals("") Then
                lenmFundSearchSummaryText = SearchSummaryText.NotValidForFunds
            End If
        End If

        'Conduct the search
        ConductSearch(lstrInvestorSearch, lstrFundSearch, lstrInvAddressSearch, lstrFundAddressSearch, lstrInvestorSearch.Length, lstrFundSearch.Length, False, SearchSummaryText.NoSuggestions, lenmFundSearchSummaryText)
    End Sub

    ''' <summary>
    ''' To mark the record as Custodian
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub MarkCustodian()
        Dim lblnZeroIsSelectedRow As Boolean = False
        Try
            If grdMapData.Selected.Rows.Count > 0 OrElse grdMapData.ActiveRow IsNot Nothing Then
                'If no row is selected, then make the active row as selected
                lblnZeroIsSelectedRow = False
                If grdMapData.Selected.Rows.Count = 0 Then
                    lblnZeroIsSelectedRow = True
                    grdMapData.Rows(grdMapData.ActiveRow.Index).Selected = True
                End If
                'Set the Map Data's record's attributes
                If chkMarkCustodian.Checked Then
                    For Each lRow As UltraGridRow In grdMapData.Selected.Rows
                        SetInvestorRelatedFields(lRow, Nothing, Nothing, InvestorMappingChangesSource.MarkCustodianTrue)
                        'lRow.Cells("InvestorID").Value = mintCustodianInvestorID
                        'lRow.Cells(mstrMappedInvName).Value = mstrCustodianInvestor
                        'lRow.Cells("MInvestorTypeID").Value = DBNull.Value
                        'lRow.Cells("InvStatusCode").Value = ""
                        'lRow.Cells("InvEntityID").Value = ""

                        SetFundRelatedFields(lRow, Nothing, Nothing, FundMappingChangesSource.MarkCustodian)
                        'lRow.Cells("FundID").Value = DBNull.Value
                        ''lRow.Cells(mstrMappedFundName).Value = mstrCustodianInvestor
                        'lRow.Cells("FundStatusCode").Value = ""
                        ''SetUniClientFundMappingStatus(lRow)
                        'lRow.Cells("LinkCount").Value = 0
                        'lRow.Cells("FundEntityID").Value = ""
                        'lRow.Cells("UserID").Value = CommonCLL.UserID
                        'lRow.Cells("Full Name").Value = CommonCLL.UserFullName
                    Next
                Else
                    For Each lRow As UltraGridRow In grdMapData.Selected.Rows
                        SetInvestorRelatedFields(lRow, Nothing, Nothing, InvestorMappingChangesSource.MarkCustodianFalse)
                        'lRow.Cells("InvestorID").Value = DBNull.Value
                        'lRow.Cells(mstrMappedInvName).Value = ""
                        'lRow.Cells("MInvestorTypeID").Value = DBNull.Value
                        'lRow.Cells("InvStatusCode").Value = ""
                        'lRow.Cells("InvEntityID").Value = ""

                        SetFundRelatedFields(lRow, Nothing, Nothing, FundMappingChangesSource.MarkCustodian)
                        'lRow.Cells("FundID").Value = DBNull.Value
                        'lRow.Cells(mstrMappedFundName).Value = ""
                        'lRow.Cells("FundStatusCode").Value = ""
                        ''SetUniClientFundMappingStatus(lRow)
                        'lRow.Cells("LinkCount").Value = 0
                        'lRow.Cells("FundEntityID").Value = ""
                        'lRow.Cells("UserID").Value = CommonCLL.UserID
                        'lRow.Cells("Full Name").Value = CommonCLL.UserFullName
                    Next
                End If
                'Unselect the row that was selected through code
                If lblnZeroIsSelectedRow Then
                    grdMapData.Rows(grdMapData.ActiveRow.Index).Selected = False
                End If
                CType(grdMapData.DataSource, DataTable).AcceptChanges()
                grdMapData.Focus()
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        End Try
    End Sub

    ''' <summary>
    ''' To set the Investor Related fields in the Map Data grid. The attributes/fields are being set from here, this is the central place to make any changes in Investor's fields.
    ''' </summary>
    ''' <param name="ldrDestinationData">The destinition data row</param>
    ''' <param name="ldrSourceData">The source data row</param>
    ''' <param name="penmMappingChangesSource">Source of change</param>
    ''' <remarks></remarks>
    Private Sub SetInvestorRelatedFields(ByRef pdrDestinationData As UltraGridRow, ByVal pdrSourceData As DataRow, ByVal pultraSourceData As UltraGridRow, ByVal penmMappingChangesSource As InvestorMappingChangesSource)
        If pdrSourceData Is Nothing AndAlso pultraSourceData Is Nothing Then
            If penmMappingChangesSource = InvestorMappingChangesSource.MarkCustodianTrue Then
                UntickAllTickedRows(grdInvestor)
                If chkCreateNewInv.Checked Then
                    chkCreateNewInv.Checked = False
                End If
                If chkCreateNewFund.Checked Then
                    chkCreateNewFund.Checked = False
                End If
                pdrDestinationData.Cells("InvestorID").Value = mintCustodianInvestorID
            Else
                pdrDestinationData.Cells("InvestorID").Value = DBNull.Value
            End If
            If penmMappingChangesSource = InvestorMappingChangesSource.NewInvMarked Then
                UntickAllTickedRows(grdInvestor)
                If chkMarkCustodian.Checked Then
                    chkMarkCustodian.Checked = False
                End If

                Dim lstrMappedInvNameText As String = ""
                If chkCreateNewInv.Checked Then
                    lstrMappedInvNameText = mstrCreateNew
                End If
                pdrDestinationData.Cells(mstrMappedInvName).Value = lstrMappedInvNameText
            ElseIf penmMappingChangesSource = InvestorMappingChangesSource.MarkCustodianTrue Then
                pdrDestinationData.Cells(mstrMappedInvName).Value = mstrCustodianInvestor
            Else
                pdrDestinationData.Cells(mstrMappedInvName).Value = ""
            End If
            pdrDestinationData.Cells("MInvestorTypeID").Value = DBNull.Value
            pdrDestinationData.Cells("InvStatusCode").Value = ""
            pdrDestinationData.Cells("InvEntityID").Value = ""
        Else
            Dim lstrInvestorCol As String = ""
            If penmMappingChangesSource = InvestorMappingChangesSource.UnmapShortCut OrElse penmMappingChangesSource = InvestorMappingChangesSource.Restore Then
                lstrInvestorCol = "InvestorName"
            ElseIf penmMappingChangesSource = InvestorMappingChangesSource.SuggestoinsFromInv Then
                lstrInvestorCol = "Name"
            ElseIf penmMappingChangesSource = InvestorMappingChangesSource.SuggestoinsFromFund Then
                lstrInvestorCol = "Linked Inv."
            Else
                lstrInvestorCol = mstrMappedInvName
            End If
            If pdrSourceData IsNot Nothing Then
                pdrDestinationData.Cells("InvestorID").Value = pdrSourceData.Item("InvestorID")
                pdrDestinationData.Cells(mstrMappedInvName).Value = pdrSourceData.Item(lstrInvestorCol)
                pdrDestinationData.Cells("MInvestorTypeID").Value = pdrSourceData.Item("MInvestorTypeID")
                If penmMappingChangesSource = InvestorMappingChangesSource.NewInvCreated Then
                    pdrDestinationData.Cells("InvStatusCode").Value = EntityStatus.ACTVE.ToString
                    pdrDestinationData.Cells("Doubts").Value = False
                Else
                    pdrDestinationData.Cells("InvStatusCode").Value = pdrSourceData.Item("InvStatusCode")
                End If
                pdrDestinationData.Cells("InvEntityID").Value = pdrSourceData.Item("InvEntityID")
            ElseIf pultraSourceData IsNot Nothing Then
                pdrDestinationData.Cells("InvestorID").Value = pultraSourceData.GetCellValue("InvestorID")
                pdrDestinationData.Cells(mstrMappedInvName).Value = pultraSourceData.GetCellValue(lstrInvestorCol)
                pdrDestinationData.Cells("MInvestorTypeID").Value = pultraSourceData.GetCellValue("MInvestorTypeID")
                If penmMappingChangesSource = InvestorMappingChangesSource.NewInvCreated Then
                    pdrDestinationData.Cells("InvStatusCode").Value = EntityStatus.ACTVE.ToString
                    pdrDestinationData.Cells("Doubts").Value = False
                Else
                    pdrDestinationData.Cells("InvStatusCode").Value = pultraSourceData.GetCellValue("InvStatusCode")
                End If
                pdrDestinationData.Cells("InvEntityID").Value = pultraSourceData.GetCellValue("InvEntityID")
            End If

            If chkMarkCustodian.Checked Then
                chkMarkCustodian.Checked = False
            End If
            If chkCreateNewInv.Checked Then
                chkCreateNewInv.Checked = False
            End If
        End If
        pdrDestinationData.Cells("UserID").Value = CommonCLL.UserID
        pdrDestinationData.Cells("Full Name").Value = CommonCLL.UserFullName
    End Sub

    ''' <summary>
    ''' To set the Fund Related fields in the Map Data grid. The attributes/fields are being set from here, this is the central place to make any changes in Fund's fields.
    ''' </summary>
    ''' <param name="ldrDestinationData">The destinition data row</param>
    ''' <param name="ldrSourceData">The source data row</param>
    ''' <param name="penmMappingChangesSource">Source of change</param>
    ''' <remarks></remarks>
    Private Sub SetFundRelatedFields(ByRef pdrDestinationData As UltraGridRow, ByVal pdrSourceData As DataRow, ByVal pultraSourceData As UltraGridRow, ByVal penmMappingChangesSource As FundMappingChangesSource)
        Dim lstrMappedFundNameText As String = ""
        Dim lstrFundCol As String = ""
        If pdrSourceData Is Nothing AndAlso pultraSourceData Is Nothing Then
            If penmMappingChangesSource = FundMappingChangesSource.NewFundMarked Then
                UntickAllTickedRows(grdFund)
                If chkMarkCustodian.Checked Then
                    chkMarkCustodian.Checked = False
                End If
                If chkCreateNewFund.Checked Then
                    lstrMappedFundNameText = mstrCreateNew
                End If
                pdrDestinationData.Cells(mstrMappedFundName).Value = lstrMappedFundNameText
            Else
                pdrDestinationData.Cells(mstrMappedFundName).Value = ""
            End If
            If penmMappingChangesSource = FundMappingChangesSource.MarkCustodian Then
                UntickAllTickedRows(grdFund)
                If chkCreateNewInv.Checked Then
                    chkCreateNewInv.Checked = False
                End If
                If chkCreateNewFund.Checked Then
                    chkCreateNewFund.Checked = False
                End If
            End If
            pdrDestinationData.Cells("FundID").Value = DBNull.Value
            pdrDestinationData.Cells("LinkCount").Value = 0
            pdrDestinationData.Cells("FundStatusCode").Value = ""
            pdrDestinationData.Cells("FundEntityID").Value = ""
        Else
            If penmMappingChangesSource = FundMappingChangesSource.UnmapShortCut OrElse penmMappingChangesSource = FundMappingChangesSource.Restore Then
                lstrFundCol = "FundName"
            ElseIf penmMappingChangesSource = FundMappingChangesSource.Suggestoins Then
                lstrFundCol = "Name"
            Else
                lstrFundCol = mstrMappedFundName
            End If
            If pdrSourceData IsNot Nothing Then
                pdrDestinationData.Cells("FundID").Value = pdrSourceData.Item("FundID")
                pdrDestinationData.Cells(mstrMappedFundName).Value = pdrSourceData.Item(lstrFundCol)
                If penmMappingChangesSource = FundMappingChangesSource.NewFundCreated Then
                    pdrDestinationData.Cells("FundStatusCode").Value = EntityStatus.ACTVE.ToString
                    pdrDestinationData.Cells("Doubts").Value = False
                    pdrDestinationData.Cells("LinkCount").Value = 0
                Else
                    pdrDestinationData.Cells("FundStatusCode").Value = pdrSourceData.Item("FundStatusCode")
                    pdrDestinationData.Cells("LinkCount").Value = pdrSourceData.Item("LinkCount")
                End If
                pdrDestinationData.Cells("FundEntityID").Value = pdrSourceData.Item("FundEntityID")
            Else
                pdrDestinationData.Cells("FundID").Value = pultraSourceData.GetCellValue("FundID")
                pdrDestinationData.Cells(mstrMappedFundName).Value = pultraSourceData.GetCellValue(lstrFundCol)
                If penmMappingChangesSource = FundMappingChangesSource.NewFundCreated Then
                    pdrDestinationData.Cells("FundStatusCode").Value = EntityStatus.ACTVE.ToString
                    pdrDestinationData.Cells("Doubts").Value = False
                    pdrDestinationData.Cells("LinkCount").Value = 0
                Else
                    pdrDestinationData.Cells("FundStatusCode").Value = pultraSourceData.GetCellValue("FundStatusCode")
                    pdrDestinationData.Cells("LinkCount").Value = pultraSourceData.GetCellValue("LinkCount")
                End If
                pdrDestinationData.Cells("FundEntityID").Value = pultraSourceData.GetCellValue("FundEntityID")
            End If
            If chkMarkCustodian.Checked Then
                chkMarkCustodian.Checked = False
            End If
            If chkCreateNewFund.Checked Then
                chkCreateNewFund.Checked = False
            End If
        End If
        pdrDestinationData.Cells("UserID").Value = CommonCLL.UserID
        pdrDestinationData.Cells("Full Name").Value = CommonCLL.UserFullName
    End Sub

#End Region

End Class